idiap_devtools.click#

Functions

validate_profile(_, __, value)

Callback for click doing a profile name validation.

verbosity_option(logger[, short_name, name, ...])

Click-option decorator that adds a -v/--verbose option to a cli.

Classes

AliasedGroup([name, commands])

Class that handles prefix aliasing for commands.

PreserveIndentCommand(name[, ...])

A click command that preserves text indentation.

idiap_devtools.click.verbosity_option(logger, short_name='v', name='verbose', dflt=0, **kwargs)[source]#

Click-option decorator that adds a -v/--verbose option to a cli.

This decorator adds a click option to your CLI to set the log-level on a provided logging.Logger. You must specifically determine the logger that will be affected by this CLI option, via the logger option.

@verbosity_option(logger=logger)

The verbosity option has the “count” type, and has a default value of 0. At each time you provide -v options on the command-line, this value is increased by one. For example, a CLI setting of -vvv will set the value of this option to 3. This is the mapping between the value of this option (count of -v CLI options passed) and the log-level set at the provided logger:

  • 0 (no -v option provided): logger.setLevel(logging.ERROR)

  • 1 (-v): logger.setLevel(logging.WARNING)

  • 2 (-vv): logger.setLevel(logging.INFO)

  • 3 (-vvv or more): logger.setLevel(logging.DEBUG)

Parameters:
  • logger (Logger) – The logging.Logger to be set.

  • short_name (str) – Short name of the option. If not set, then use v

  • name (str) – Long name of the option. If not set, then use verbose – this will also become the name of the contextual parameter for click.

  • dlft – The default verbosity level to use (defaults to 0).

  • **kwargs (Any) – Further keyword-arguments to be forwarded to the underlying click.option()

Return type:

Callable[..., Any]

Returns:

A callable, that follows the click-framework policy for option decorators. Use it accordingly.

class idiap_devtools.click.AliasedGroup(name=None, commands=None, **attrs)[source]#

Bases: Group

Class that handles prefix aliasing for commands.

get_command(ctx, cmd_name)[source]#

Returns the decorated command.

Parameters:
  • ctx (Context) – The current command context being parsed

  • cmd_name (str) – The subcommand name that was called

Return type:

Optional[Command]

Returns:

The decorated command with aliasing capabilities

class idiap_devtools.click.PreserveIndentCommand(name, context_settings=None, callback=None, params=None, help=None, epilog=None, short_help=None, options_metavar='[OPTIONS]', add_help_option=True, no_args_is_help=False, hidden=False, deprecated=False)[source]#

Bases: Command

A click command that preserves text indentation.

format_epilog(_, formatter)[source]#

Formats the command epilog during –help.

Parameters:
  • _ – The current parsing context

  • formatter (HelpFormatter) – The formatter to use for printing text

Return type:

None

format_description(_, formatter)[source]#

Formats the command description during –help.

Parameters:
  • _ – The current parsing context

  • formatter (HelpFormatter) – The formatter to use for printing text

Return type:

None

idiap_devtools.click.validate_profile(_, __, value)[source]#

Callback for click doing a profile name validation.

Parameters:
  • _ – current command context

  • __ – The option being validated

  • value (str) – The value set for the option

Return type:

str

Returns:

The validated option value