Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
[CLI] Control commands order in help message
Browse files Browse the repository at this point in the history
This way, running 'canopy --help' prints the errors in the order matching the quick start
  • Loading branch information
igiloh-pinecone committed Nov 5, 2023
1 parent 71c7fc6 commit 3e63f95
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/canopy_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,29 @@ def _load_kb_config(config_file: Optional[str]) -> Dict[str, Any]:
return kb_config


@click.group(invoke_without_command=True, context_settings=CONTEXT_SETTINGS)
class CanopyCommandGroup(click.Group):
"""
A custom click Group that lets us control the order of commands in the help menu.
"""
def __init__(self, name=None, commands=None, **attrs):
super().__init__(name, commands, **attrs)
self._commands_order = {
"new": 0,
"upsert": 1,
"start": 2,
"chat": 3,
"health": 4,
"stop": 5,
"api-docs": 6,

}

def list_commands(self, ctx):
return sorted(self.commands, key=lambda x: self._commands_order.get(x, 1000))


@click.group(invoke_without_command=True, context_settings=CONTEXT_SETTINGS,
cls=CanopyCommandGroup)
@click.version_option(__version__, "-v", "--version", prog_name="Canopy")
@click.pass_context
def cli(ctx):
Expand Down Expand Up @@ -608,4 +630,4 @@ def api_docs(url):


if __name__ == "__main__":
cli()
cli()

0 comments on commit 3e63f95

Please sign in to comment.