bin.base

Base command-line interface.

Module Contents

Classes

Error(self,reason,status=None) Exception raised by commands.
UsageError() Exception raised for malformed arguments.
Extensions(self,namespace,register) Loads extensions from setuptools entrypoints.
Command(self,app=None,get_app=None,no_color=False,stdout=None,stderr=None,quiet=False,on_error=None,on_usage_error=None) Base class for command-line applications.

Functions

_optparse_callback_to_type(option,callback)
_add_optparse_argument(parser,opt,typemap=dict)
_add_compat_options(parser,options)
daemon_options(parser,default_pidfile=None,default_logfile=None) Add daemon options to argparse parser.
_optparse_callback_to_type(option, callback)
_add_optparse_argument(parser, opt, typemap=dict)
_add_compat_options(parser, options)
class Error(reason, status=None)

Exception raised by commands.

__init__(reason, status=None)
__str__()
class UsageError

Exception raised for malformed arguments.

class Extensions(namespace, register)

Loads extensions from setuptools entrypoints.

__init__(namespace, register)
add(cls, name)
load()
class Command(app=None, get_app=None, no_color=False, stdout=None, stderr=None, quiet=False, on_error=None, on_usage_error=None)

Base class for command-line applications.

Arguments:

app (Celery): The app to use. get_app (Callable): Fucntion returning the current app

when no app provided.
__init__(app=None, get_app=None, no_color=False, stdout=None, stderr=None, quiet=False, on_error=None, on_usage_error=None)
run(*args, **options)
on_error(exc)
on_usage_error(exc)
on_concurrency_setup()
__call__(*args, **kwargs)
verify_args(given, _index=0)
execute_from_commandline(argv=None)

Execute application from command-line.

Arguments:
argv (List[str]): The list of command-line arguments.
Defaults to sys.argv.
run_from_argv(prog_name, argv=None, command=None)
maybe_patch_concurrency(argv=None)
usage(command)
add_arguments(parser)
get_options()
add_preload_arguments(parser)
_add_version_argument(parser)
prepare_arguments(parser)
expanduser(value)
ask(q, choices, default=None)

Prompt user to choose from a tuple of string values.

If a default is not specified the question will be repeated until the user gives a valid choice.

Matching is case insensitive.

Arguments:
q (str): the question to ask (don’t include questionark) choice (Tuple[str]): tuple of possible choices, must be lowercase. default (Any): Default value if any.
handle_argv(prog_name, argv, command=None)

Parse arguments from argv and dispatch to run().

Warning:
Exits with an error message if supports_args is disabled and argv contains positional arguments.
Arguments:
prog_name (str): The program name (argv[0]). argv (List[str]): Rest of command-line arguments.
prepare_args(options, args)
check_args(args)
error(s)
out(s, fh=None)
die(msg, status=EX_FAILURE)
early_version(argv)
parse_options(prog_name, arguments, command=None)

Parse the available options.

create_parser(prog_name, command=None)
_format_epilog(epilog)
_format_description(description)
add_compat_options(parser, options)
prepare_parser(parser)
setup_app_from_commandline(argv)
_handle_user_preload_options(argv)
find_app(app)
symbol_by_name(name, imp=None)
process_cmdline_config(argv)
parse_preload_options(args)
_parse_preload_options(args, options)
add_append_opt(acc, opt, value)
parse_doc(doc)
_strip_restructeredtext(s)
with_pool_option(argv)

Return tuple of (short_opts, long_opts).

Returns only if the command supports a pool argument, and used to monkey patch eventlet/gevent environments as early as possible.

Example:
>>> has_pool_option = (['-P'], ['--pool'])
node_format(s, nodename, **extra)
host_format(s, **extra)
_get_default_app(*args, **kwargs)
pretty_list(n)
pretty_dict_ok_error(n)
say_remote_command_reply(replies)
pretty(n)
say_chat(direction, title, body="")
colored()
colored(obj)
no_color()
no_color(value)
daemon_options(parser, default_pidfile=None, default_logfile=None)

Add daemon options to argparse parser.