ScriptParser

class ScriptParser[source]

Bases: object

Build a command-line interface to a python function

Inspects the function signature to create command-line arguments. It converts argument arg to long option –arg. Parsing is similar to python, supporting mix of positional and named arguments (note its possible to specify named arguments before positional arguments). Also supports use of *args and **kwargs.

Help messages are constructed by parsing the doc-string of the wrapped function.

Can be used as a decorator if function should only be used as a script

__init__(func, allow_reset=False)[source]

Wrap func as a command-line interface

Parameters:

func – Callable

Methods

__init__

Wrap func as a command-line interface

parse

run

run the wrapped function with arguments passed on sys.argv or as list of string arguments

parse(args=None)[source]
run(args=None)[source]

run the wrapped function with arguments passed on sys.argv or as list of string arguments