pyats.cli package

Submodules

class pyats.cli.base.Command(prog)

Bases: pyats.cli.base._BaseCommand

Command class

Subclass this to implement a new command that can be used under CLI

error(msg)

api to raise an error to the user

main(argv)

internal entrypoint for commands

parse_args(argv)
run(args)

api to be implemented by the designer, performs the dirty work your command is designed to do

class pyats.cli.base.CommandWithSubcommands(*args, **kwargs)

Bases: pyats.cli.base.Command

CommandWithSubcommands class

Subclass this to implement a new command with subcommands under CLI

The difference between this and the Command() class is this class doesn’t directly perform actions - and defer actions to its subcommands.

SUBCMDS_BASECLS

alias of pyats.cli.base.Subcommand

SUBCMDS_ENTRYPOINT = None
SUBCOMMANDS = []
load_subcmds()
run(args)

api to be implemented by the designer, performs the dirty work your command is designed to do

usage = '{prog} <subcommand> [options]'
class pyats.cli.base.Subcommand(parent)

Bases: pyats.cli.base._BaseCommand

Subcommand class

defines a subcommand under under another command.

error(msg)

api to raise an error to the user

run(args)

runs this subcommand

class pyats.cli.core.CLI(prog='pyats', usage='pyats <command> [options]', epilog="\n    Run 'pyats <command> --help' for more information on a command.\n", commands=None)

Bases: object

COMMANDS = []
COMMANDS_BASECLS

alias of pyats.cli.base.Command

COMMANDS_ENTRYPOINT = 'pyats.cli.commands'
configure_logging()
load_commands(commands=None)
main(argv=None)

CLI handler main entrypoint

class pyats.cli.formatter.CustomHelpFormatter(*args, **kwargs)

Bases: argparse.HelpFormatter

add_usage(usage, actions, groups, prefix='Usage:\n  ')

usage: -> Usage:

class pyats.cli.parser.CustomParser(**kwargs)

Bases: argparse.ArgumentParser

error(message: string)

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.

pyats.cli.utils.chunks(l, n)

Yield successive n-sized chunks from l.

pyats.cli.utils.cmd(command, cwd=None, env=None, incl_stderr=True)

Run a command and log its output as soon as it is produced.

pyats.cli.utils.cmd_timed(command, cwd=None, env=None, incl_stderr=True, timeout=None)

Run a command with an optional timeout. Log output after command done.

pyats.cli.utils.format_list(data, header=None, indent=2, columns=2)
pyats.cli.utils.format_table(data, header=None, indent=2)

formats a table nicely using header, data rows, and defaults to indenting to the right 2 spaces for looks.

pyats.cli.utils.load_dict_from_cli(cli_args: list)dict

Try to load a dictionary from a list of cli argument values.

Parameters

cli_args (list of strings) – Values from command line argument

Returns

dictionary if loaded sucessfully

pyats.cli.utils.retrieve_argument(cli_arg)str

Retrieve the value from the provided cli argument.

Will check if a URL has been provided and try to load the contents from the URL. If the value is a file, try to load the contents from the file. If no value could be loaded from URL or file, return the original argument value.

Parameters

cli_arg – Value of CLI argument

Returns

contents of the CLI argument if URL or file, or same value

pyats.cli.utils.tabulate(vals)
pyats.cli.utils.yes_or_no(question, default='')