Skip to content

Commit

Permalink
chore: add subcommands description in help
Browse files Browse the repository at this point in the history
Signed-off-by: reidliu <[email protected]>
  • Loading branch information
reidliu committed Feb 22, 2025
1 parent b890d7a commit e1b7380
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions llama_stack/cli/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self):
prog="llama",
description="Welcome to the Llama CLI",
add_help=True,
formatter_class=argparse.RawTextHelpFormatter,
)

# Default command is to print help
Expand All @@ -33,12 +34,21 @@ def __init__(self):
Download.create(subparsers)
VerifyDownload.create(subparsers)

self.print_subcommand_description(subparsers)

def parse_args(self) -> argparse.Namespace:
return self.parser.parse_args()

def run(self, args: argparse.Namespace) -> None:
args.func(args)

def print_subcommand_description(self, subparsers: argparse._SubParsersAction):
description_text = ""
for name, subcommand in subparsers.choices.items():
description = subcommand.description
description_text += f" {name:<21} {description}\n"
self.parser.epilog = description_text


def main():
parser = LlamaCLIParser()
Expand Down
10 changes: 10 additions & 0 deletions llama_stack/cli/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, subparsers: argparse._SubParsersAction):
"model",
prog="llama model",
description="Work with llama models",
formatter_class=argparse.RawTextHelpFormatter,
)

self.parser.set_defaults(func=lambda args: self.parser.print_help())
Expand All @@ -37,3 +38,12 @@ def __init__(self, subparsers: argparse._SubParsersAction):
ModelDescribe.create(subparsers)
ModelVerifyDownload.create(subparsers)
ModelRemove.create(subparsers)

self.print_subcommand_description(subparsers)

def print_subcommand_description(self, subparsers: argparse._SubParsersAction):
description_text = ""
for name, subcommand in subparsers.choices.items():
description = subcommand.description
description_text += f" {name:<21} {description}\n"
self.parser.epilog = description_text
10 changes: 10 additions & 0 deletions llama_stack/cli/stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, subparsers: argparse._SubParsersAction):
"stack",
prog="llama stack",
description="Operations for the Llama Stack / Distributions",
formatter_class=argparse.RawTextHelpFormatter,
)

self.parser.add_argument(
Expand All @@ -39,3 +40,12 @@ def __init__(self, subparsers: argparse._SubParsersAction):
StackListApis.create(subparsers)
StackListProviders.create(subparsers)
StackRun.create(subparsers)

self.print_subcommand_description(subparsers)

def print_subcommand_description(self, subparsers: argparse._SubParsersAction):
description_text = ""
for name, subcommand in subparsers.choices.items():
description = subcommand.description
description_text += f" {name:<21} {description}\n"
self.parser.epilog = description_text

0 comments on commit e1b7380

Please sign in to comment.