ilcli package

Submodules

ilcli.actions module

class ilcli.actions.DocAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: argparse.Action

class ilcli.actions.ServeRestAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: argparse.Action

ilcli.args module

ilcli.args.kv_args_to_dict(arg_list)[source]

Convert a list of key-value args with the form:

--key value

into a dictionary. In case of parsing failure, cmd.parser.error will be called, making the program existing with error status.

Parameters

arg_list – the list of arguments (typically the parameter of _validate_extra_arguments()).

ilcli.command module

class ilcli.command.Command(parser=None, parent=None, name=None, out=None, err=None)[source]

Bases: object

Base class defining default behaviour for commands. Create a child class in order to create a cli.

add_argument(*args, **kwargs)[source]
Add an argument to the internal parser. It accepts the same syntax as

argparse.ArgumentParser.add_argument().

Parameters
  • args – arguments to pass to argparse.ArgumentParser

  • kwargs – key-value arguments to pass to argparse.ArgumentParser

err(*args)[source]

Print a message into error output (by default, to sys.stderr):

 > self.err('hello')
 'hello\n'
 > self.err('hello %s!', 'world')
 'hello world!\n'
> self.err()
'\n'
Params args

list of parameters where first element is the message and the rest optional arguments will be applied to the first argument as string template arguments.

ignore_arguments = []
inherit_arguments = True

inherit arguments from parent commands

init_arguments()[source]

Initialise internal parser with the arguments for this command.

This is the default implementation. Children classes must use _init_arguments().

name = None

the name of the command (if None, class name by default)

out(*args)[source]

Print a message into the output (by default, sys.stdout):

> self.out('hello')
'hello\n'
> self.out('hello %s!', 'world')
'hello world!\n'
> self.out()
'\n'
Params args

list of parameters where first element is the message and the rest optional arguments will be applied to the first argument as string template arguments.

parser_args = {}

additional arguments to pass to the ArgumentParser and all sub-parsers

run(args=None)[source]

Run the command.

This is the default implementation. Children classes must use _run() method.

Parameters

args – list of arguments. Default sys.argv.

subcommands = []

the list classes of subcommands

Module contents

class ilcli.Command(parser=None, parent=None, name=None, out=None, err=None)[source]

Bases: object

Base class defining default behaviour for commands. Create a child class in order to create a cli.

add_argument(*args, **kwargs)[source]
Add an argument to the internal parser. It accepts the same syntax as

argparse.ArgumentParser.add_argument().

Parameters
  • args – arguments to pass to argparse.ArgumentParser

  • kwargs – key-value arguments to pass to argparse.ArgumentParser

err(*args)[source]

Print a message into error output (by default, to sys.stderr):

 > self.err('hello')
 'hello\n'
 > self.err('hello %s!', 'world')
 'hello world!\n'
> self.err()
'\n'
Params args

list of parameters where first element is the message and the rest optional arguments will be applied to the first argument as string template arguments.

ignore_arguments = []
inherit_arguments = True

inherit arguments from parent commands

init_arguments()[source]

Initialise internal parser with the arguments for this command.

This is the default implementation. Children classes must use _init_arguments().

name = None

the name of the command (if None, class name by default)

out(*args)[source]

Print a message into the output (by default, sys.stdout):

> self.out('hello')
'hello\n'
> self.out('hello %s!', 'world')
'hello world!\n'
> self.out()
'\n'
Params args

list of parameters where first element is the message and the rest optional arguments will be applied to the first argument as string template arguments.

parser_args = {}

additional arguments to pass to the ArgumentParser and all sub-parsers

run(args=None)[source]

Run the command.

This is the default implementation. Children classes must use _run() method.

Parameters

args – list of arguments. Default sys.argv.

subcommands = []

the list classes of subcommands