cloup._sections
¶
Classes¶
|
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. |
Attributes¶
Contents¶
-
cloup._sections.
CommandType
¶
-
cloup._sections.
Subcommands
¶
-
class
cloup._sections.
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
title (str) –
commands (Union[Iterable[click.core.Command], Dict[str, click.core.Command]]) –
sorted (bool) –
-
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._sections.
SectionMixin
(*args, commands=None, sections=(), align_sections=None, **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.
Changed in version 0.8.0: This mixin now relies on
cloup.HelpFormatter
to align help sections. If aclick.HelpFormatter
is used with aTypeError
is raised.Changed in version 0.8.0: Removed
format_section
. Addedmake_commands_help_section
.New in version 0.5.0.
- Parameters
commands (Optional[Dict[str, click.core.Command]]) –
sections (Iterable[cloup._sections.Section]) –
align_sections (Optional[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]
-
make_commands_help_section
(self, section)[source]¶ - Parameters
section (Section) –
- Return type
Optional[cloup.formatting.HelpSection]
-
must_align_sections
(self, ctx, default=True)[source]¶ - Parameters
ctx (Optional[click.Context]) –
default (bool) –
- Return type
-
format_commands
(self, ctx, formatter)[source]¶ - Parameters
ctx (click.Context) –
formatter (click.HelpFormatter) –
- Return type