Parguments

class parguments.Parguments(doc, version=None, options_first=False)

Parguments is a python library to help you create human friendly cli written on top of docopt.

Example

"""
catsup v1.0

Usage:
    catsup init [<path>]
    catsup build
    catsup deploy
    catsup -h | --help
    catsup --version

Options:
    -h --help             Show this screen and exit.
    -s --settings=<file>  path to config file. [default: config.json]
"""
from parguments import Parguments

parguments = Parguments(__doc__, version='1.0')

@parguments.command
def init(path):
  """
  Usage:
    catsup init [<path>]

  Options:
    -h --help             Show this screen and exit.
    -s --settings=<file>  path to setting file. [default: config.json]
  """
  pass

@parguments.command
def build(settings):
  """
  Usage:
    catsup build [-s <file>|--settings=<file>]

  Options:
    -h --help             Show this screen and exit.
    -s --settings=<file>  path to setting file. [default: config.json]
  """
  pass

@parguments.command
def deploy(settings):
  """
  Usage:
    catsup deploy [-s <file>|--settings=<file>]

  Options:
    -h --help             Show this screen and exit.
    -s --settings=<file>  path to setting file. [default: config.json]
  """
  pass

if __name__ == '__main__':
  parguments.run()
Parameters:
  • doc (str) – description of your program.
  • version (any object) – the object will be printed if --version is in argv
  • options_first (bool) –

    Set to True to require options precede positional arguments,

    i.e. to forbid options and positional arguments intermix.

command(func)

Decorator to add a command function to the registry.

Parameters:func – command function.
add_command(func, name=None, doc=None)

Add a command function to the registry.

Parameters:
  • func – command function.
  • name – default name of func.
  • doc – description of the func.default docstring of func.
run(command=None, argv=None, help=True, exit=True)

Parse arguments and run the funcs.

Parameters:
  • command – name of command to run. default argv[0]
  • argv – argument vector to be parsed. sys.argv[1:] is used if not provided.
  • help – Set to False to disable automatic help on -h or –help options.
  • exit – Set to False to return result instead of exiting.
Fork me on GitHub