cloup._sections

Classes

Section(title[, commands, sorted])

A group of (sub)commands to show in the same help section of a MultiCommand.

SectionMixin(*args[, commands, sections, …])

Adds to a click.MultiCommand the possibility to organize its subcommands in multiple help sections.

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 from SectionMixin.

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 old GroupSection.

Parameters
classmethod sorted(cls, title, commands=())[source]
Parameters
  • title (str) –

  • commands (Subcommands) –

Return type

Section

add_command(self, cmd, name=None)[source]
Parameters
list_commands(self)[source]
Return type

List[Tuple[str, click.Command]]

__len__(self)[source]
Return type

int

__repr__(self)[source]

Return repr(self).

Return type

str

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:

  1. passing a list of Section objects to the constructor setting the argument sections

  2. using add_section() to add a single section

  3. using 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 a click.HelpFormatter is used with a TypeError is raised.

Changed in version 0.8.0: Removed format_section. Added make_commands_help_section.

New in version 0.5.0.

Parameters
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
Return type

Section

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
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
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
Return type

bool

format_commands(self, ctx, formatter)[source]
Parameters
Return type

None