cloup
¶
Top-level package for cloup.
Subpackages¶
Classes summary¶
|
A click.Option with an extra field |
|
|
|
Implements support to option groups. |
|
A group of (sub)commands to show in the same help section of a |
|
Adds to a click.MultiCommand the possibility to organize its subcommands in multiple help sections. |
|
A |
|
A |
|
A |
|
Provides support to constraints. |
Functions Summary¶
|
|
|
Attaches an option group to the command. This decorator is overloaded with two signatures::. |
|
Decorator that creates a new command using the wrapped function as callback. |
|
Decorator for creating a new |
|
Registers a constraint. |
Contents¶
-
cloup.
__email__
= gianluca.gippetto@gmail.com¶
-
cloup.
__version__
¶
-
cloup.
__version_tuple__
¶
-
class
cloup.
GroupedOption
(*args, group=None, **attrs)[source]¶ Bases:
click.Option
A click.Option with an extra field
group
of type OptionGroup- Parameters
group (Optional[cloup._option_groups.OptionGroup]) –
-
class
cloup.
OptionGroup
(name, help=None, constraint=None)[source]¶ - Parameters
name (str) –
help (Optional[str]) –
constraint (Optional[cloup.constraints._core.Constraint]) –
-
get_help_records
(self, ctx)[source]¶ - Parameters
ctx (click.Context) –
-
class
cloup.
OptionGroupMixin
(*args, align_option_groups=True, **kwargs)[source]¶ Implements support to option groups.
New in version 0.5.0.
Important
In order to check the constraints defined on the option groups, a command must inherits from
cloup.ConstraintMixin
too!- Parameters
align_option_groups (bool) –
-
get_ungrouped_options
(self, ctx)[source]¶ - Parameters
ctx (click.Context) –
- Return type
Sequence[click.Option]
-
get_option_group_title
(self, ctx, opt_group)[source]¶ - Parameters
ctx (click.Context) –
opt_group (OptionGroup) –
- Return type
-
format_option_group
(self, ctx, formatter, opt_group, help_records=None)[source]¶ - Parameters
ctx (click.Context) –
formatter (click.HelpFormatter) –
opt_group (OptionGroup) –
help_records (Optional[Sequence]) –
-
format_options
(self, ctx, formatter, max_option_width=30)[source]¶ - Parameters
ctx (click.Context) –
formatter (click.HelpFormatter) –
max_option_width (int) –
-
cloup.
option
(*param_decls, group=None, cls=GroupedOption, **attrs)[source]¶ - Parameters
group (Optional[cloup._option_groups.OptionGroup]) –
cls (Type[click.core.Option]) –
- Return type
Callable[[C], C]
-
cloup.
option_group
(name: str, help: str, *options: OptionDecorator, constraint: Optional[cloup.constraints.Constraint] = None) → OptionGroupDecorator[source]¶ -
cloup.
option_group
(name: str, *options: OptionDecorator, help: Optional[str] = None, constraint: Optional[cloup.constraints.Constraint] = None) → OptionGroupDecorator Attaches an option group to the command. This decorator is overloaded with two signatures:
@option_group(name: str, *options, help: Optional[str] = None) @option_group(name: str, help: str, *options)
In other words, if the second position argument is a string, it is interpreted as the “help” argument. Otherwise, it is interpreted as the first option; in this case, you can still pass the help as keyword argument.
- Parameters
name – a mandatory name/title for the group
help – an optional help string for the group
options – option decorators like click.option
constraint – a
Constraint
to validate on this option group
- Returns
a decorator that attaches the contained options to the decorated function
-
class
cloup.
Section
(title, commands=(), sorted=False)[source]¶ A group of (sub)commands to show in the same help section of a
MultiCommand
. You can use sections with any Command that inherits fromSectionMixin
.Changed in version 0.6.0: Removed the deprecated old name
GroupSection
.Changed in version 0.5.0: Introduced the new name
Section
and deprecated the oldGroupSection
.- Parameters
-
add_command
(self, cmd, name=None)[source]¶ - Parameters
cmd (click.Command) –
name (Optional[str]) –
-
list_commands
(self)[source]¶ - Return type
List[Tuple[str, click.Command]]
-
class
cloup.
SectionMixin
(*args, commands=None, sections=(), align_sections=True, **kwargs)[source]¶ Adds to a click.MultiCommand the possibility to organize its subcommands in multiple help sections.
Sections can be specified in the following ways:
passing a list of
Section
objects to the constructor setting the argumentsections
using
add_section()
to add a single sectionusing
add_command()
with the argument section set
Commands not assigned to any user-defined section are added to the “default section”, whose title is “Commands” or “Other commands” depending on whether it is the only section or not. The default section is the last shown section in the help and its commands are listed in lexicographic order.
New in version 0.5.0.
- Parameters
commands (Optional[Dict[str, click.core.Command]]) –
sections (Iterable[cloup._sections.Section]) –
align_sections (bool) –
-
add_section
(self, section)[source]¶ Adds a
Section
to this group. You can add the same section object a single time.- Parameters
section (Section) –
-
section
(self, title, *commands, **attrs)[source]¶ Creates a new
Section
, adds it to this group and returns it.- Parameters
title (str) –
commands (click.Command) –
- Return type
-
add_command
(self, cmd, name=None, section=None)[source]¶ Adds a new command. If
section
is None, the command is added to the default section.- Parameters
cmd (click.Command) –
name (Optional[str]) –
section (Optional[Section]) –
-
list_sections
(self, ctx, include_default_section=True)[source]¶ Returns the list of all sections in the “correct order”. if
include_default_section=True
and the default section is non-empty, it will be included at the end of the list.- Parameters
ctx (click.Context) –
include_default_section (bool) –
- Return type
List[Section]
-
format_commands
(self, ctx, formatter)[source]¶ - Parameters
ctx (click.Context) –
formatter (click.HelpFormatter) –
-
format_section
(self, ctx, formatter, section, command_col_width=None)[source]¶ - Parameters
ctx (click.Context) –
formatter (click.HelpFormatter) –
section (Section) –
command_col_width (Optional[int]) –
-
class
cloup.
Command
(*click_args, constraints=(), show_constraints=False, align_option_groups=True, **click_kwargs)[source]¶ Bases:
cloup.constraints.ConstraintMixin
,cloup._option_groups.OptionGroupMixin
,click.Command
A
click.Command
supporting option groups and constraints.- Parameters
constraints (Sequence[cloup.constraints._support.BoundConstraintSpec]) –
show_constraints (bool) –
align_option_groups (bool) –
-
class
cloup.
Group
(name=None, commands=None, sections=(), align_sections=True, **attrs)[source]¶ Bases:
cloup._sections.SectionMixin
,click.Group
A
click.Group
that allows to organize its subcommands in multiple help sections and and whose subcommands are, by default, of typecloup.Command
.This class is just a
click.Group
mixed withSectionMixin
that overrides the decoratorscommand()
andgroup()
so that asection
for the created subcommand can be specified.See the docstring of the two superclasses for more details.
- Parameters
name (Optional[str]) –
commands (Optional[Dict[str, click.core.Command]]) –
sections (Iterable[cloup._sections.Section]) –
align_sections (bool) –
-
command
(self, name=None, cls=None, section=None, **kwargs)[source]¶ Creates a new command and adds it to this group.
- Parameters
name (Optional[str]) –
cls (Optional[Type[click.Command]]) –
section (Optional[cloup._sections.Section]) –
- Return type
Callable[[Callable], click.Command]
-
group
(self, name=None, cls=None, section=None, **kwargs)[source]¶ A shortcut decorator for declaring and attaching a group to the group. This takes the same arguments as
group()
but immediately registers the created command with this instance by calling intoadd_command()
.- Parameters
name (Optional[str]) –
cls (Optional[Type[click.Group]]) –
section (Optional[cloup._sections.Section]) –
-
class
cloup.
MultiCommand
(*args, commands=None, sections=(), align_sections=True, **kwargs)[source]¶ Bases:
cloup._sections.SectionMixin
,click.MultiCommand
A
click.MultiCommand
that allows to organize its subcommands in multiple help sections and and whose subcommands are, by default, of typecloup.Command
.This class is just a
click.MultiCommand
mixed withSectionMixin
. See the docstring of the two superclasses for more details.- Parameters
commands (Optional[Dict[str, click.core.Command]]) –
sections (Iterable[cloup._sections.Section]) –
align_sections (bool) –
-
cloup.
command
(name=None, cls=Command, **attrs)[source]¶ Decorator that creates a new command using the wrapped function as callback.
The only differences with respect to
click.commands
are:this decorator creates a
cloup.Command
by default;this decorator supports
@constraint
.
- Parameters
name (Optional[str]) – name of the command
cls (Type[click.core.Command]) – type of click.Command
attrs – any argument you can pass to
click.command()
- Return type
Callable[[Callable], click.core.Command]
-
cloup.
group
(name=None, cls=Group, **attrs)[source]¶ Decorator for creating a new
Group
.Note
If you use static type checking, note that the
cls
optional argument of this function must be of typecloup.Group
, notclick.Group
.- Parameters
name (Optional[str]) – name of the command
cls (Type[cloup._commands.Group]) – type of
cloup.Group
attrs – any argument you can pass to
click.group()
- Return type
Callable[[Callable], cloup._commands.Group]
-
class
cloup.
ConstraintMixin
(*args, constraints=(), show_constraints=False, **kwargs)[source]¶ Provides support to constraints.
- Parameters
constraints (Sequence[cloup.constraints._support.BoundConstraintSpec]) –
show_constraints (bool) –
-
get_params_by_name
(self, names)[source]¶ - Parameters
names (Iterable[str]) –
- Return type
List[click.Parameter]
-
format_help
(self, ctx, formatter)[source]¶ - Parameters
formatter (click.HelpFormatter) –
- Return type
-
cloup.
constraint
(constr, params)[source]¶ Registers a constraint.
- Parameters
constr (cloup.constraints._core.Constraint) –
params (Iterable[str]) –