Slight changes in CLI structure for performance reasons
Having the plugin commands on the first level of --help proved to be a bad idea since it basically kills every chance of lazy loading the (expensive) plugin context. Using a sub command for anything plugin related allows us to only fire up the plugin context if a plugin command is expected, saving us some precious seconds of operation in all other cases. For conformity reasons the dev sub commands were now restructured similarly.
This commit is contained in:
1 parent
221b497932
commit
8ed3bcb094
3 files changed
+25
-29
No files matched your search
+12
-13
@@ -15,8 +15,8 @@ class OctoPrintDevelCommands(click.MultiCommand):
|
||||
based on availability of development dependencies.
|
||||
"""
|
||||
|
||||
prefix = "dev"
|
||||
sep = ":"
|
||||
groups = ("plugin",)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
click.MultiCommand.__init__(self, *args, **kwargs)
|
||||
@@ -47,10 +47,11 @@ class OctoPrintDevelCommands(click.MultiCommand):
|
||||
yield result
|
||||
|
||||
def _get_commands(self):
|
||||
commands = dict()
|
||||
for command in self._get_commands_from_prefix_methods("group_"):
|
||||
commands[self.prefix + self.sep + command.name] = command
|
||||
return commands
|
||||
result = dict()
|
||||
for group in self.groups:
|
||||
for command in self._get_commands_from_prefix_methods("{}_".format(group)):
|
||||
result[group + self.sep + command.name] = command
|
||||
return result
|
||||
|
||||
def list_commands(self, ctx):
|
||||
result = [name for name in self._get_commands()]
|
||||
@@ -61,13 +62,6 @@ class OctoPrintDevelCommands(click.MultiCommand):
|
||||
commands = self._get_commands()
|
||||
return commands.get(cmd_name, None)
|
||||
|
||||
def group_plugin(self):
|
||||
command_group = click.Group("plugin",
|
||||
help="Helpers for plugin developers")
|
||||
for command in self._get_commands_from_prefix_methods("plugin_"):
|
||||
command_group.add_command(command)
|
||||
return command_group
|
||||
|
||||
def plugin_new(self):
|
||||
try:
|
||||
import cookiecutter.main
|
||||
@@ -229,6 +223,11 @@ class OctoPrintDevelCommands(click.MultiCommand):
|
||||
|
||||
return command
|
||||
|
||||
@click.group(cls=OctoPrintDevelCommands)
|
||||
@click.group()
|
||||
def dev_commands():
|
||||
pass
|
||||
|
||||
@dev_commands.group(name="dev", cls=OctoPrintDevelCommands)
|
||||
def dev():
|
||||
"""Additional commands for development tasks."""
|
||||
pass
|
||||
Reference in new issue
Block a user