snakeoil.cli.tool module

Generic support for running commandline tools.

class snakeoil.cli.tool.FormattingHandler(formatter)[source]

Bases: Handler

Logging handler printing through a formatter.

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

class snakeoil.cli.tool.Tool(parser, outfile=None, errfile=None)[source]

Bases: object

Abstraction for commandline tools.

handle_exec_exception(e)[source]

Handle custom runtime exceptions.

main()[source]

Execute the main script function.

parse_args(args=None, namespace=None)[source]

Parse the given arguments using argparse.

Parameters:
  • args (sequence of strings) – arguments to parse, defaulting to C{sys.argv[1:]}.

  • namespace (argparse.Namespace object) – Namespace object to use for created attributes.

post_parse(options)[source]

Handle custom options after argparsing.

pre_parse(args, namespace)[source]

Handle custom options before argparsing.