colrev.ui_cli.cli.SpecialHelpOrder

class SpecialHelpOrder(*args, **kwargs)[source]

Bases: Group

Order for cli commands in help page overview

Methods

add_command

Registers another Command with this group.

collect_usage_pieces

Returns all the pieces that go into the usage line and returns it as a list of strings.

command

Behaves the same as click.Group.command() except capture a priority for listing command names in help.

format_commands

Extra format methods for multi methods that adds all the commands after the options.

format_epilog

Writes the epilog into the formatter if it exists.

format_help

Writes the help into the formatter if it exists.

format_help_text

Writes the help text to the formatter if it exists.

format_options

Writes all the options into the formatter if they exist.

format_usage

Writes the usage line into the formatter.

get_command

Given a context and a command name, this returns a Command object if it exists or returns None.

get_command_hidden

Returns the short help of a subcommand

get_command_short_help

Returns the short help of a subcommand

get_help

Formats the help into a string and returns it.

get_help_option

Returns the help option object.

get_help_option_names

Returns the names for the help option.

get_params

rtype:

List[Parameter]

get_short_help_str

Gets short help for the command or makes it by shortening the long help string.

get_usage

Formats the usage line into a string and returns it.

group

A shortcut decorator for declaring and attaching a group to the group.

invoke

Given a context, this invokes the attached callback (if it exists) in the right way.

list_commands

Returns a list of subcommand names in the order they should appear.

list_commands_for_help

reorder the list of commands when listing the help

main

This is the way to invoke a script with all the bells and whistles as a command line application.

make_context

This function when given an info name and arguments will kick off the parsing and create a new Context.

make_parser

Creates the underlying option parser for this command.

parse_args

Given a context and a list of arguments this creates the parser and parses the arguments, then modifies the context as necessary.

resolve_command

rtype:

Tuple[Optional[str], Optional[Command], List[str]]

result_callback

Adds a result callback to the command.

shell_complete

Return a list of completions for the incomplete value.

to_info_dict

Gather information that could be useful for a tool generating user-facing documentation.

Attributes

allow_extra_args

the default for the Context.allow_extra_args flag.

allow_interspersed_args

the default for the Context.allow_interspersed_args flag.

command_class

If set, this is used by the group's command() decorator as the default Command class.

group_class

If set, this is used by the group's group() decorator as the default Group class.

ignore_unknown_options

the default for the Context.ignore_unknown_options flag.

add_command(cmd, name=None)

Registers another Command with this group. If the name is not provided, the name of the command is used.

Return type:

None

allow_extra_args = True

the default for the Context.allow_extra_args flag.

allow_interspersed_args = False

the default for the Context.allow_interspersed_args flag.

callback

the callback to execute when the command fires. This might be None in which case nothing happens.

collect_usage_pieces(ctx)

Returns all the pieces that go into the usage line and returns it as a list of strings.

Return type:

List[str]

command(*args, **kwargs)[source]

Behaves the same as click.Group.command() except capture a priority for listing command names in help.

command_class: t.Optional[t.Type[Command]] = None

If set, this is used by the group’s command() decorator as the default Command class. This is useful to make all subcommands use a custom command class.

New in version 8.0.

commands: t.MutableMapping[str, Command]

The registered subcommands by their exported names.

context_class

alias of Context

context_settings: t.MutableMapping[str, t.Any]

an optional dictionary with defaults passed to the context.

format_commands(ctx, formatter)

Extra format methods for multi methods that adds all the commands after the options.

Return type:

None

format_epilog(ctx, formatter)

Writes the epilog into the formatter if it exists.

Return type:

None

format_help(ctx, formatter)

Writes the help into the formatter if it exists.

This is a low-level method called by get_help().

This calls the following methods: :rtype: None

format_help_text(ctx, formatter)

Writes the help text to the formatter if it exists.

Return type:

None

format_options(ctx, formatter)

Writes all the options into the formatter if they exist.

Return type:

None

format_usage(ctx, formatter)

Writes the usage line into the formatter.

This is a low-level method called by get_usage().

Return type:

None

get_command(ctx, cmd_name)

Given a context and a command name, this returns a Command object if it exists or returns None.

Return type:

Optional[Command]

get_command_hidden(ctx, cmd_name)

Returns the short help of a subcommand

It allows MultiCommand subclasses to implement more efficient ways to provide the subcommand hidden attribute, for example by leveraging some caching.

Parameters

ctxclick.core.Context

The current context

cmd_name :

The sub command name

Returns

bool

The sub command hidden status

get_command_short_help(ctx, cmd_name)

Returns the short help of a subcommand

It allows MultiCommand subclasses to implement more efficient ways to provide the subcommand short help, for example by leveraging some caching.

Parameters

ctxclick.core.Context

The current context

cmd_name :

The sub command name

Returns

str

The sub command short help

get_help(ctx)[source]

Formats the help into a string and returns it.

Calls format_help() internally.

get_help_option(ctx)

Returns the help option object.

Return type:

Optional[Option]

get_help_option_names(ctx)

Returns the names for the help option.

Return type:

List[str]

get_short_help_str(limit=45)

Gets short help for the command or makes it by shortening the long help string.

Return type:

str

get_usage(ctx)

Formats the usage line into a string and returns it.

Calls format_usage() internally.

Return type:

str

group(*args, **kwargs)

A shortcut decorator for declaring and attaching a group to the group. This takes the same arguments as group() and immediately registers the created group with this group by calling add_command().

To customize the group class used, set the group_class attribute. :rtype: Union[Callable[[Callable[..., Any]], Group], Group]

Changed in version 8.1: This decorator can be applied without parentheses.

Changed in version 8.0: Added the group_class attribute.

group_class: t.Optional[t.Union[t.Type['Group'], t.Type[type]]] = None

If set, this is used by the group’s group() decorator as the default Group class. This is useful to make all subgroups use a custom group class.

If set to the special value type (literally group_class = type), this group’s class will be used as the default class. This makes a custom group class continue to make custom groups.

New in version 8.0.

ignore_unknown_options = False

the default for the Context.ignore_unknown_options flag.

invoke(ctx)

Given a context, this invokes the attached callback (if it exists) in the right way.

Return type:

Any

list_commands(ctx)

Returns a list of subcommand names in the order they should appear.

Return type:

List[str]

list_commands_for_help(ctx)[source]

reorder the list of commands when listing the help

Return type:

Generator

main(args=None, prog_name=None, complete_var=None, standalone_mode=True, windows_expand_args=True, **extra)

This is the way to invoke a script with all the bells and whistles as a command line application. This will always terminate the application after a call. If this is not wanted, SystemExit needs to be caught.

This method is also available by directly calling the instance of a Command.

Parameters:
  • args (Optional[Sequence[str]]) – the arguments that should be used for parsing. If not provided, sys.argv[1:] is used.

  • prog_name (Optional[str]) – the program name that should be used. By default the program name is constructed by taking the file name from sys.argv[0].

  • complete_var (Optional[str]) – the environment variable that controls the bash completion support. The default is "_<prog_name>_COMPLETE" with prog_name in uppercase.

  • standalone_mode (bool) – the default behavior is to invoke the script in standalone mode. Click will then handle exceptions and convert them into error messages and the function will never return but shut down the interpreter. If this is set to False they will be propagated to the caller and the return value of this function is the return value of invoke().

  • windows_expand_args (bool) – Expand glob patterns, user dir, and env vars in command line args on Windows.

  • extra (Any) – extra keyword arguments are forwarded to the context constructor. See Context for more information.

Return type:

Any

Changed in version 8.0.1: Added the windows_expand_args parameter to allow disabling command line arg expansion on Windows.

Changed in version 8.0: When taking arguments from sys.argv on Windows, glob patterns, user dir, and env vars are expanded.

Changed in version 3.0: Added the standalone_mode parameter.

make_context(info_name, args, parent=None, **extra)

This function when given an info name and arguments will kick off the parsing and create a new Context. It does not invoke the actual command callback though.

To quickly customize the context class used without overriding this method, set the context_class attribute.

Parameters:
  • info_name (Optional[str]) – the info name for this invocation. Generally this is the most descriptive name for the script or command. For the toplevel script it’s usually the name of the script, for commands below it’s the name of the command.

  • args (List[str]) – the arguments to parse as list of strings.

  • parent (Optional[Context]) – the parent context if available.

  • extra (Any) – extra keyword arguments forwarded to the context constructor.

Return type:

Context

Changed in version 8.0: Added the context_class attribute.

make_parser(ctx)

Creates the underlying option parser for this command.

Return type:

OptionParser

name

the name the command thinks it has. Upon registering a command on a Group the group will default the command name with this information. You should instead use the Context's info_name attribute.

params: t.List['Parameter']

the list of parameters for this command in the order they should show up in the help page and execute. Eager parameters will automatically be handled before non eager ones.

parse_args(ctx, args)

Given a context and a list of arguments this creates the parser and parses the arguments, then modifies the context as necessary. This is automatically invoked by make_context().

Return type:

List[str]

result_callback(replace=False)

Adds a result callback to the command. By default if a result callback is already registered this will chain them but this can be disabled with the replace parameter. The result callback is invoked with the return value of the subcommand (or the list of return values from all subcommands if chaining is enabled) as well as the parameters as they would be passed to the main callback.

Example:

@click.group()
@click.option('-i', '--input', default=23)
def cli(input):
    return 42

@cli.result_callback()
def process_result(result, input):
    return result + input
Parameters:

replace (bool) – if set to True an already existing result callback will be removed.

Return type:

Callable[[TypeVar(F, bound= Callable[..., Any])], TypeVar(F, bound= Callable[..., Any])]

Changed in version 8.0: Renamed from resultcallback.

New in version 3.0.

shell_complete(ctx, incomplete)

Return a list of completions for the incomplete value. Looks at the names of options, subcommands, and chained multi-commands.

Parameters:
  • ctx (Context) – Invocation context for this command.

  • incomplete (str) – Value being completed. May be empty.

Return type:

List[CompletionItem]

New in version 8.0.

to_info_dict(ctx)

Gather information that could be useful for a tool generating user-facing documentation. This traverses the entire structure below this command.

Use click.Context.to_info_dict() to traverse the entire CLI structure.

Parameters:

ctx (Context) – A Context representing this command.

Return type:

Dict[str, Any]

New in version 8.0.