Boolean attributes must be given a default value.
When set defaulted to False, CliMe will use ArguementParsers's action="store_false".
Using the flag will set it to True
import attr
from clime import clime
@attr.s(auto_attribs=True)
class Dude:
likes_ice_cream: bool = False
def declare_ice_cream_status(self):
negate = " do not" if not self.likes_ice_cream else ""
print(f"hi! i{negate} like ice cream")
def main():
clime(Dude).declare_ice_cream_status()
if __name__ == "__main__":
main()
$ python tutorial_001.py --help
usage: tutorial_001.py [-h] [--likes-ice-cream]
optional arguments:
-h, --help show this help message and exit
--likes-ice-cream (default: False)
Super!
note: CliMe converts underscores from variable names to dashes in the CLI
In the this case 'likes_ice_cream' became 'likes-ice-cream'
Running without arguments will keep that attribute False.
Try it!
$ python tutorial_001.py
hi! i do not like ice cream
True.
$ python tutorial_001.py --likes-ice-cream
hi! i like ice cream
That's it. For boolean arguments just set a default value!