Skip to main content

Posts

Showing posts with the label docopt

How to use DocOpt to generate Command Line Interface (CLI) tools

DocOpt is library that can generate beautiful command line interfaces using python. It is an alternative to ArgParse/OptParse and makes generating CLI interfaces a breeze. When generating CLI using ArgParse/OptParse we need to create a hierarchy of modules and submodules and link them together.  This process is tedious and debugging the errors is cumbersome. Instead, DocOpt parses the docstring (__doc__) of the file and generates a parser automatically. The docstring should be defined based on POSIX command description syntax. An example: $fincalc -h Usage: fincalc (si|simple-interest) -p <principal> -i <interest> -t <tenure> [--daily] [--plot-graph] fincalc (fd|fixed-deposit) -p <principal> -i <interest> -t <tenure> [--plot-graph] fincalc sip -p <principal> -i <interest> -t <tenure> [--plot-graph] fincalc emi -p <principal> -i <interest> -t <tenure> fincalc cagr -p <principal> -r <return...