mirror of https://github.com/devine-dl/devine.git
List available Services on error
This is mainly to lessen confusion on service name typo's or new users getting used to the CLI. It also changed the Exceptions on the methods of Service from ClickException to a KeyError since they are intended to be used on the core codebase outside of the context of Click.
This commit is contained in:
parent
df2f9b85ae
commit
a24633fe61
|
@ -37,7 +37,15 @@ class Services(click.MultiCommand):
|
|||
def get_command(self, ctx: click.Context, name: str) -> click.Command:
|
||||
"""Load the Service and return the Click CLI method."""
|
||||
tag = Services.get_tag(name)
|
||||
try:
|
||||
service = Services.load(tag)
|
||||
except KeyError as e:
|
||||
available_services = self.list_commands(ctx)
|
||||
if not available_services:
|
||||
raise click.ClickException(
|
||||
f"There are no Services added yet, therefore the '{name}' Service could not be found."
|
||||
)
|
||||
raise click.ClickException(f"{e}. Available Services: {', '.join(available_services)}")
|
||||
|
||||
if hasattr(service, "cli"):
|
||||
return service.cli
|
||||
|
@ -58,7 +66,7 @@ class Services(click.MultiCommand):
|
|||
for service in _SERVICES:
|
||||
if service.parent.stem == tag:
|
||||
return service.parent
|
||||
raise click.ClickException(f"Unable to find service by the name '{name}'")
|
||||
raise KeyError(f"There is no Service added by the Tag '{name}'")
|
||||
|
||||
@staticmethod
|
||||
def get_tag(value: str) -> str:
|
||||
|
@ -80,7 +88,7 @@ class Services(click.MultiCommand):
|
|||
"""Load a Service module by Service tag."""
|
||||
module = _MODULES.get(tag)
|
||||
if not module:
|
||||
raise click.ClickException(f"Unable to find Service by the tag '{tag}'")
|
||||
raise KeyError(f"There is no Service added by the Tag '{tag}'")
|
||||
return module
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue