consolekit.commands

Customised click commands and command groups.

New in version 0.8.0.

Classes:

ContextInheritingGroup([name, commands])

Subclass of click.Group whose children inherit its context_settings.

MarkdownHelpCommand(name[, …])

Subclass of click.Command which treats the help text as markdown and prints a rendered representation.

MarkdownHelpGroup([name, commands])

Subclass of click.Group which treats the help text as markdown and prints a rendered representation.

MarkdownHelpMixin()

Mixin class for click.Command and click.Group which treats the help text as markdown and prints a rendered representation.

RawHelpCommand(name[, context_settings, …])

Subclass of click.Command which leaves the help text unformatted.

RawHelpGroup([name, commands])

Subclass of click.Group which leaves the help text unformatted.

RawHelpMixin()

Mixin class for click.Command and click.Group which leaves the help text unformatted.

SuggestionGroup([name, commands])

Subclass of click.Group which suggests the most similar command if the command is not found.

class ContextInheritingGroup(name=None, commands=None, **attrs)[source]

Bases: Group

Subclass of click.Group whose children inherit its context_settings.

The group’s commands can be given different context settings by passing the context_settings keyword argument to command() and group() as normal.

New in version 1.1.0.

Methods:

command(*args, **kwargs)

A shortcut decorator for declaring and attaching a command to the group.

group(*args, **kwargs)

A shortcut decorator for declaring and attaching a group to the group.

command(*args, **kwargs)[source]

A shortcut decorator for declaring and attaching a command to the group.

This takes the same arguments as click.command() but immediately registers the created command with this instance by calling into click.Group.add_command().

Return type

Callable[[Callable[…, Any]], Command]

group(*args, **kwargs)[source]

A shortcut decorator for declaring and attaching a group to the group.

This takes the same arguments as click.group() but immediately registers the created group with this instance by calling into click.Group.add_command().

Return type

Callable[[Callable[…, Any]], Group]

class MarkdownHelpCommand[source]
class MarkdownHelpGroup[source]

Bases: MarkdownHelpMixin

Subclasses of click.Command and click.Group which treat the help text as markdown and print a rendered representation.

Tested in Gnome Terminal and Terminator (both libVTE-based), and PyCharm. libVTE has the best support. PyCharm’s support for italics and strikethrough is poor. Support on Windows is, as expected, poor.

Not tested on other terminals, but contributions are welcome to improve support.

New in version 0.8.0.

MarkdownHelpCommand.parse_args(ctx, args)

Parse the given arguments and modify the context as necessary.

Parameters
Return type

List[str]

class MarkdownHelpMixin[source]

Bases: object

Mixin class for click.Command and click.Group which treats the help text as markdown and prints a rendered representation.

Tip

This can be combined with groups such as SuggestionGroup.

Tested in Gnome Terminal and Terminator (both libVTE-based), and PyCharm. libVTE has the best support. PyCharm’s support for italics and strikethrough is poor. Support on Windows is, as expected, poor.

Not tested on other terminals, but contributions are welcome to improve support.

New in version 0.8.0.

format_help_text(ctx, formatter)[source]

Writes the help text to the formatter if it exists.

Parameters
class RawHelpCommand[source]
class RawHelpGroup[source]

Bases: RawHelpMixin

Subclasses of click.Command and click.Group which leave the help text unformatted.

New in version 0.8.0.

class RawHelpMixin[source]

Bases: object

Mixin class for click.Command and click.Group which leaves the help text unformatted.

Tip

This can be combined with groups such as SuggestionGroup.

New in version 0.8.0.

format_help_text(ctx, formatter)[source]

Writes the help text to the formatter if it exists.

Parameters
class SuggestionGroup(name=None, commands=None, **attrs)[source]

Bases: ContextInheritingGroup

Subclass of click.Group which suggests the most similar command if the command is not found.

Changed in version 0.8.0: Moved to consolekit.commands.

Changed in version 1.1.0: Now inherits from ContextInheritingGroup

resolve_command(ctx, args)[source]

Resolve the requested command belonging to this group, and print a suggestion if it can’t be found.

Parameters
Return type

Tuple[str, Command, List[str]]

Returns

The name of the matching command, the click.Command object itself, and any remaining arguments.