:orphan: :mod:`cloup._sections` ====================== .. py:module:: cloup._sections Classes ------- .. autosummary:: ~cloup._sections.Section ~cloup._sections.SectionMixin Attributes ---------- .. autoapisummary:: cloup._sections.CommandType cloup._sections.Subcommands Contents -------- .. py:data:: CommandType .. py:data:: Subcommands .. py:class:: Section(title, commands = (), is_sorted = False) 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 :class:`SectionMixin`. .. versionchanged:: 0.6.0 removed the deprecated old name ``GroupSection``. .. versionchanged:: 0.5.0 introduced the new name ``Section`` and deprecated the old ``GroupSection``. :param title: :param commands: sequence of commands or dict of commands keyed by name :param is_sorted: if True, ``list_commands()`` returns the commands in lexicographic order .. py:method:: sorted(cls, title, commands = ()) :classmethod: .. py:method:: add_command(self, cmd, name = None) .. py:method:: list_commands(self) .. py:method:: __len__(self) .. py:method:: __repr__(self) Return repr(self). .. py:class:: SectionMixin(*args, commands = None, sections = (), align_sections = None, **kwargs) Adds to a :class:`click.MultiCommand` the possibility of organizing its subcommands into multiple help sections. Sections can be specified in the following ways: #. passing a list of :class:`Section` objects to the constructor setting the argument ``sections`` #. using :meth:`add_section` to add a single section #. using :meth:`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. .. versionchanged:: 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. .. versionchanged:: 0.8.0 removed ``format_section``. Added ``make_commands_help_section``. .. versionadded:: 0.5.0 :param align_sections: whether to align the columns of all subcommands' help sections. This is also available as a context setting having a lower priority than this attribute. Given that this setting should be consistent across all you commands, you should probably use the context setting only. :param args: positional arguments forwarded to the next class in the MRO :param kwargs: keyword arguments forwarded to the next class in the MRO .. py:method:: add_section(self, section) Add a :class:`Section` to this group. You can add the same section object a single time. .. py:method:: section(self, title, *commands, **attrs) Create a new :class:`Section`, adds it to this group and returns it. .. py:method:: add_command(self, cmd, name = None, section = None, fallback_to_default_section = True) Add a subcommand to this ``Group``. **Implementation note:** ``fallback_to_default_section`` looks not very clean but, even if it's not immediate to see (it wasn't for me), I chose it over apparently cleaner options. :param cmd: :param name: :param section: a ``Section`` instance. The command must not be in the section already. :param fallback_to_default_section: if ``section`` is None and this option is enabled, the command is added to the "default section". If disabled, the command is not added to any section unless ``section`` is provided. This is useful for internal code and subclasses. Don't disable it unless you know what you are doing. .. py:method:: list_sections(self, ctx, include_default_section = True) Return 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. .. py:method:: format_subcommand_name(self, ctx, name, cmd) Used to format the name of the subcommands. This method is useful when you combine this extension with other click extensions that override :meth:`format_commands`. Most of these, like click-default-group, just add something to the name of the subcommands, which is exactly what this method allows you to do without overriding bigger methods. .. py:method:: make_commands_help_section(self, ctx, section) .. py:method:: must_align_sections(self, ctx, default = True) .. py:method:: format_commands(self, ctx, formatter)