<plugin identifier>:<command> => plugin:<plugin identifier> command

This commit is contained in:
Gina Häußge 2015-10-30 10:14:21 +01:00
parent ec491c3d0d
commit c6f1088ccf
2 changed files with 28 additions and 11 deletions

View file

@ -78,18 +78,29 @@ octoprint.cli.commands
--help Show this message and exit.
Commands:
custom_cli_command:greet Greet someone by name, the greeting can be...
custom_cli_command:random Greet someone by name with a random greeting.
daemon Starts, stops or restarts in daemon mode.
devel:newplugin Creates a new plugin based on the OctoPrint...
dev:plugin Helpers for plugin developers
plugin:custom_cli_command custom_cli_command commands
serve Starts the OctoPrint server.
$ octoprint plugin:custom_cli_command --help
Usage: octoprint plugin:custom_cli_command [OPTIONS] COMMAND [ARGS]...
custom_cli_command commands
Options:
--help Show this message and exit.
Commands:
greet Greet someone by name, the greeting can be...
random Greet someone by name with a random greeting.
Each also has an individual help output:
.. code-block:: none
$ octoprint custom_cli_command:greet --help
Usage: octoprint custom_cli_command:greet [OPTIONS] [NAME]
$ octoprint plugin:custom_cli_command greet --help
Usage: octoprint plugin:custom_cli_command greet [OPTIONS] [NAME]
Greet someone by name, the greeting can be customized.
@ -97,8 +108,8 @@ octoprint.cli.commands
-g, --greeting TEXT The greeting to use
--help Show this message and exit.
$ octoprint custom_cli_command:random --help
Usage: octoprint custom_cli_command:random [OPTIONS] [NAME]
$ octoprint plugin:custom_cli_command random --help
Usage: octoprint plugin:custom_cli_command random [OPTIONS] [NAME]
Greet someone by name with a random greeting.
@ -109,13 +120,13 @@ octoprint.cli.commands
.. code-block:: none
$ octoprint custom_cli_command:greet
$ octoprint plugin:custom_cli_command greet
Hello World!
$ octoprint custom_cli_command:greet --greeting "Good morning"
$ octoprint plugin:custom_cli_command greet --greeting "Good morning"
Good morning World!
$ octoprint custom_cli_command:random stranger
$ octoprint plugin:custom_cli_command random stranger
Hola stranger!
.. note::

View file

@ -27,6 +27,7 @@ class OctoPrintPluginCommands(click.MultiCommand):
The :class:`~octoprint.plugin.core.PluginManager` instance.
"""
prefix = "plugin"
sep = ":"
def __init__(self, *args, **kwargs):
@ -75,12 +76,17 @@ class OctoPrintPluginCommands(click.MultiCommand):
for name, hook in self.hooks.items():
try:
plugin_info = self.plugin_manager.get_plugin_info(name, require_enabled=False)
command_group = click.Group(name=name, help="{} commands".format(plugin_info.name))
commands = hook(self, pass_octoprint_ctx)
for command in commands:
if not isinstance(command, click.Command):
self._logger.warn("Plugin {} provided invalid CLI command, ignoring it: {!r}".format(name, command))
continue
result[name + self.sep + command.name] = command
command_group.add_command(command)
result[self.prefix + self.sep + name] = command_group
except:
self._logger.exception("Error while retrieving cli commants for plugin {}".format(name))