Package: cltoolbox
cltoolbox: Easy Command Line Interfacescltoolbox is a wrapper aroundargparse, and allows you to write complete CLI
applications in seconds using a simple decorator.Significant portions of this code are based onmando.  The primary
differences betweenmandoandcltoolboxare:cltoolboxsupports automatic detection of Sphinx, Google, and Numpy
docstring formats by using thedocstring_parserlibrarycltoolboxsupports python 3.7+If you need support of themandoformatted docstring or python 2 you have to
usemandoinstead ofcltoolbox.Installationpippipinstallcltoolboxcondacondainstall-cconda-forgecltoolboxThe problemTheargparsemodule that comes with Python requires a programmer to
duplicate information that Python can easily parse from the function signature
and docstring.  Thecltoolboxdoes this for you by using decorators.Quickstartfromcltoolboximportcommand,main@commanddefecho(text,capitalize=False):"""Echo the given text."""ifcapitalize:text=text.upper()print(text)if__name__=="__main__":main()Generated help:$pythonexample.py-husage: example.py [-h] {echo} ...

positional arguments:
  {echo}
    echo      Echo the given text.

optional arguments:
  -h, --help  show this help message and exit$pythonexample.pyecho-husage: example.py echo [-h] [--capitalize] text

Echo the given text.

positional arguments:
  text

optional arguments:
  -h, --help    show this help message and exit
  --capitalizeActual usage:$pythonexample.pyechospamspam$pythonexample.pyecho--capitalizespamSPAMArealexampleSomething more complex and real-world-ish. The code:fromcltoolboximportcommand,main@commanddefpush(repository,all=False,dry_run=False,force=False,thin=False):"""Update remote refs along with associated objects.

    :param repository: Repository to push to.
    :param --all: Push all refs.
    :param -n, --dry-run: Dry run.
    :param -f, --force: Force updates.
    :param --thin: Use thin pack."""print("Pushing to{0}. All:{1}, dry run:{2}, force:{3}, thin:{4}".format(repository,all,dry_run,force,thin))if__name__=="__main__":main()cltoolbox understands Sphinx, Google, and Numpy dostrings, from which it can
create short options and their help for you.$pythongit.pypush-husage: git.py push [-h] [--all] [-n] [-f] [--thin] repository

Update remote refs along with associated objects.

positional arguments:
  repository     Repository to push to.

optional arguments:
  -h, --help     show this help message and exit
  --all          Push all refs.
  -n, --dry-run  Dry run.
  -f, --force    Force updates.
  --thin         Use thin pack.Let’s try it!$pythongit.pypush--allmyrepoPushing to myrepo. All: True, dry run: False, force: False, thin: False$pythongit.pypush--all-fmyrepoPushing to myrepo. All: True, dry run: False, force: True, thin: False$pythongit.pypush--all-fnmyrepoPushing to myrepo. All: True, dry run: True, force: True, thin: False$pythongit.pypush--thin-fnmyrepoPushing to myrepo. All: False, dry run: True, force: True, thin: True$pythongit.pypush--thinusage: git.py push [-h] [--all] [-n] [-f] [--thin] repository
git.py push: error: too few argumentsAmazed uh? Yes, cltoolbox got the short options and the help from the docstring!
You can put much more in the docstring, and if that isn’t enough, there’s an@argdecorator to customize the arguments that get passed to argparse.Type annotationscltoolbox understands Python 3-style type annotations and will warn the user if the
arguments given to a command are of the wrong type.fromcltoolboximportcommand,main@commanddefduplicate(string,times:int):"""Duplicate text.

    :param string: The text to duplicate.
    :param times: How many times to duplicate."""print(string*times)if__name__=="__main__":main()$python3test.pyduplicate"test "5test test test test test$python3test.pyduplicate"test "foousage: test.py duplicate [-h] string times
test.py duplicate: error: argument times: invalid int value: 'foo'Thecltoolboxsupports shell autocompletion via theargcompletepackage and supports custom format classes. For a complete
documentation, visithttps://timcera.bibucket.io/cltoolbox/.