To use default values, just add a default value to the attribute
import attr
from clime import clime
@attr.s(auto_attribs=True)
class Dude:
name: str = "joe" # attributes with default values in the class will be set as optional arguments in the cli
def state_name(self):
print(f"hi! my name is {self.name}")
def main():
clime(Dude).state_name()
if __name__ == "__main__":
main()
$ python tutorial_002.py --help
usage: tutorial_002.py [-h] [--name NAME]
optional arguments:
-h, --help show this help message and exit
--name NAME (default: joe)
Super!
Name is now a positional argument with a defaul value. The default value is added to the --help.
Try it!
$ python tutorial_002.py
hi! my name is joe
$ python tutorial_002.py --name mike
hi! my name is mike
Want to know what will not work? Positional arguments:
$ python tutorial_002.py mike
usage: tutorial_002.py [-h] [--name NAME]
tutorial_002.py: error: unrecognized arguments: mike
Anyways... that's it. All you need to take use default values is give the attribute a default value!