cmdkit.cli#


Reference#


class Interface(program: str, usage_text: str, help_text: str, disable_colors: bool = False, formatter: ~typing.Callable[[str], str] = <function colorize_usage>, **kwargs)[source]#

Bases: ArgumentParser

Variant of argparse.ArgumentParser that raises an ArgumentError instead of calling sys.exit(). See the standard library documentation for details on add_argument() and other common methods.

The usage_text and help_text are taken verbatim; however, these text values can be colorized automatically using a generalized syntax highlighter (cmdkit.ansi.colorize_usage() by default). To disable this behavior, use the disable_colors parameter.


See also

The argparse module from the standard library, specifically the ArgumentParser class for the API. The Interface class simply modifies the behavior of ArgumentParser to not exit but instead raise exceptions, as well as disable the auto-documentation aspect for usage and help statements.


Note

The following exceptions allow the Application class to catch events and handle them instead of the default behavior in ArgumentParser to print and call exit().


class HelpOption[source]#

Bases: Exception

Raised by Interface when the help option is passed.


class VersionOption[source]#

Bases: Exception

Raised by Interface whenever action='version'.


class ArgumentError[source]#

Bases: Exception

Raised by Interface on bad arguments.