Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add subcommands description in help #1219

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llama_stack/cli/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .download import Download
from .model import ModelParser
from .stack import StackParser
from .utils import print_subcommand_description
from .verify_download import VerifyDownload


Expand All @@ -20,6 +21,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,6 +35,8 @@ def __init__(self):
Download.create(subparsers)
VerifyDownload.create(subparsers)

print_subcommand_description(self.parser, subparsers)

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

Expand Down
4 changes: 4 additions & 0 deletions llama_stack/cli/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from llama_stack.cli.model.remove import ModelRemove
from llama_stack.cli.model.verify_download import ModelVerifyDownload
from llama_stack.cli.subcommand import Subcommand
from llama_stack.cli.utils import print_subcommand_description


class ModelParser(Subcommand):
Expand All @@ -24,6 +25,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 +39,5 @@ def __init__(self, subparsers: argparse._SubParsersAction):
ModelDescribe.create(subparsers)
ModelVerifyDownload.create(subparsers)
ModelRemove.create(subparsers)

print_subcommand_description(self.parser, subparsers)
4 changes: 4 additions & 0 deletions llama_stack/cli/stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from importlib.metadata import version

from llama_stack.cli.subcommand import Subcommand
from llama_stack.cli.utils import print_subcommand_description

from .build import StackBuild
from .list_apis import StackListApis
Expand All @@ -22,6 +23,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 +41,5 @@ def __init__(self, subparsers: argparse._SubParsersAction):
StackListApis.create(subparsers)
StackListProviders.create(subparsers)
StackRun.create(subparsers)

print_subcommand_description(self.parser, subparsers)
14 changes: 14 additions & 0 deletions llama_stack/cli/stack/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.


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