snakeoil.cli.arghparse module¶
Various argparse actions, types, and miscellaneous extensions.
- class snakeoil.cli.arghparse.ArgumentParser(suppress=False, subcmds=False, color=True, debug=True, quiet=True, verbose=True, version=True, add_help=True, sorted_help=False, description=None, docs=None, script=None, prog=None, **kwargs)[source]¶
Bases:
OptionalsParser
,CsvActionsParser
Extended, argparse-compatible argument parser.
- add_subparsers(**kwargs)[source]¶
Enable docs keyword argument support for argparse arguments.
This is used to add extended, rST-formatted docs to man pages (or other generated doc formats) without affecting the regular, summarized help output for scripts.
To use, import this module where argparse is used to create parsers so the ‘docs’ keyword gets discarded during regular use. For document generation, enable the global _generate_docs variable in order to replace the summarized help strings with the extended doc strings.
- bind_reset_defaults(functor)[source]¶
Decorator to bind a function for resetting defaults before every parse run.
- error(message, status=2)[source]¶
Print an error message and exit.
Similar to argparse’s error() except usage information is not shown by default.
- parsers¶
Return the ordered sequence of inherited parsers.
- subparsers¶
Return the set of registered subparsers.
- class snakeoil.cli.arghparse.CommaSeparatedElements(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
_AppendAction
Split comma-separated disabled/neutral/enabled elements into lists.
Disabled elements are prefixed with “-”, enabled elements are prefixed with “+”, and neutral elements are unprefixed.
For example, from the sequence “-a,b,c,-d” would result in “a” and “d” being registered as disabled while “b” and “c” are enabled.
- class snakeoil.cli.arghparse.CommaSeparatedElementsAppend(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
CommaSeparatedElements
Split comma-separated enabled and disabled values and append to lists.
Multiple specified options append to instead of override the parsed args list.
- class snakeoil.cli.arghparse.CommaSeparatedNegations(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
_AppendAction
Split comma-separated enabled and disabled values into lists.
Disabled values are prefixed with “-” while enabled values are entered as is.
For example, from the sequence “-a,b,c,-d” would result in “a” and “d” being registered as disabled while “b” and “c” are enabled.
- class snakeoil.cli.arghparse.CommaSeparatedNegationsAppend(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
CommaSeparatedNegations
Split comma-separated enabled and disabled values and append to lists.
Multiple specified options append to instead of override the parsed args list.
- class snakeoil.cli.arghparse.CommaSeparatedValues(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
_AppendAction
Split comma-separated values into a list.
- class snakeoil.cli.arghparse.CommaSeparatedValuesAppend(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
CommaSeparatedValues
,ExtendAction
Split comma-separated values and append them to a list.
Multiple specified options append to instead of override the parsed args list.
- class snakeoil.cli.arghparse.CsvActionsParser(*args, **kwargs)[source]¶
Bases:
ArgumentParser
Parser with custom, CSV actions registered for usage.
- class snakeoil.cli.arghparse.CsvHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]¶
Bases:
HelpFormatter
Add custom help formatting for comma-separated value actions.
- class snakeoil.cli.arghparse.Delayed(option_strings, dest, target=None, priority=0, **kwargs)[source]¶
Bases:
Action
- class snakeoil.cli.arghparse.DelayedDefault(invokable, priority=0)[source]¶
Bases:
DelayedValue
- class snakeoil.cli.arghparse.DelayedParse(invokable, priority=0)[source]¶
Bases:
DelayedValue
- class snakeoil.cli.arghparse.EnableDebug(option_strings, dest, default=False, required=False, help=None)[source]¶
Bases:
_StoreTrueAction
- class snakeoil.cli.arghparse.Expansion(option_strings, dest, nargs=None, help=None, required=None, subst=None)[source]¶
Bases:
Action
- class snakeoil.cli.arghparse.ExtendAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
_AppendAction
Force multiple values to always be stored in a flat list.
- class snakeoil.cli.arghparse.FileType(mode='r', bufsize=-1, encoding=None, errors=None)[source]¶
Bases:
FileType
Extended file object factory supporting binary modes for stdin/stdout.
See https://bugs.python.org/issue14156 for a discussion of the issue.
- class snakeoil.cli.arghparse.ManHelpAction(option_strings, dest='==SUPPRESS==', default='==SUPPRESS==', help=None)[source]¶
Bases:
_HelpAction
Display man pages for long –help option and abbreviated output for -h.
- class snakeoil.cli.arghparse.Namespace(**kwargs)[source]¶
Bases:
Namespace
Add support for popping attrs from the namespace.
- class snakeoil.cli.arghparse.OptionalsParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)[source]¶
Bases:
ArgumentParser
Argument parser supporting parsing only optional arguments.
- parse_known_optionals(args=None, namespace=None)[source]¶
Parse known optional arguments until the first positional or -h/–help.
This is used to allow multiple shortcuts (like -c or -h) at both the global command level and the subcommand level. Otherwise, the argparse module wouldn’t allow two of the same shortcuts to exist at the same time.
- class snakeoil.cli.arghparse.OrderedParse(invokable, priority=0)[source]¶
Bases:
DelayedValue
- class snakeoil.cli.arghparse.ParseNonblockingStdin(*args, **kwargs)[source]¶
Bases:
Action
Accept arguments from standard input in a non-blocking fashion.
- class snakeoil.cli.arghparse.ParseStdin(*args, **kwargs)[source]¶
Bases:
ExtendAction
Accept arguments from standard input in a blocking fashion.
- class snakeoil.cli.arghparse.SortedHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]¶
Bases:
CsvHelpFormatter
Help formatter that sorts arguments by option strings.
- class snakeoil.cli.arghparse.StoreBool(option_strings, dest, nargs=None, const=None, default=None, required=False, help=None, metavar='BOOLEAN')[source]¶
Bases:
_StoreAction
- class snakeoil.cli.arghparse.SubcmdAbbrevArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)[source]¶
Bases:
ArgumentParser
Argparse-compatible argument parser that supports abbreviating subcommands.
- class snakeoil.cli.arghparse.Verbosity(option_strings, dest, default=None, required=False, help=None)[source]¶
Bases:
Action
- snakeoil.cli.arghparse.bounded_int(func, desc, x)[source]¶
Check if argument is an integer and matches defined bounds.
- snakeoil.cli.arghparse.create_dir(value)[source]¶
Check if argument path exists and is a directory, if it doesn’t exist create it.