You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clize is an argument parser for Python. You can
use Clize as an alternative to argparse if you want an even easier way to
create command-line interfaces.
With Clize, you can:
Create command-line interfaces by creating functions and passing them to
clize.run.
Enjoy a CLI automatically created from your functions' parameters.
Bring your users familiar --help messages generated from your docstrings.
Reuse functionality across multiple commands using decorators.
Extend Clize with new parameter behavior.
Here's an example:
fromclizeimportrundefhello_world(name=None, *, no_capitalize=False):
"""Greets the world or the given name. :param name: If specified, only greet this person. :param no_capitalize: Don't capitalize the given name. """ifname:
ifnotno_capitalize:
name=name.title()
return'Hello {0}!'.format(name)
return'Hello world!'if__name__=='__main__':
run(hello_world)
The python code above can now be used on the command-line as follows:
$ pip install clize
$ python3 hello.py --help Usage: hello.py [OPTIONS] name Greets the world or the given name. Positional arguments: name If specified, only greet this person. Options: --no-capitalize Don't capitalize the given name. Other actions: -h, --help Show the help
$ python3 hello.pyHello world!
$ python3 hello.py johnHello John!
$ python3 hello.py dave --no-capitalizeHello dave!