snakeoil.cli.tool module

Generic support for running commandline tools.

class snakeoil.cli.tool.FormattingHandler(formatter: 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.

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

Bases: object

Abstraction for commandline tools.

args
err: Formatter
handle_exec_exception(e)[source]

Handle custom runtime exceptions.

main(args=None)[source]

Execute the main script function.

options
out: Formatter
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.

parser
post_parse(options)[source]

Handle custom options after argparsing.

pre_parse(args, namespace)[source]

Handle custom options before argparsing.