diff --git a/llama_stack/cli/llama.py b/llama_stack/cli/llama.py index f0466facd..fb9eae236 100644 --- a/llama_stack/cli/llama.py +++ b/llama_stack/cli/llama.py @@ -9,6 +9,7 @@ import argparse from .download import Download from .model import ModelParser from .stack import StackParser +from .utils import print_subcommand_description from .verify_download import VerifyDownload @@ -20,6 +21,7 @@ class LlamaCLIParser: prog="llama", description="Welcome to the Llama CLI", add_help=True, + formatter_class=argparse.RawTextHelpFormatter, ) # Default command is to print help @@ -33,6 +35,8 @@ class LlamaCLIParser: Download.create(subparsers) VerifyDownload.create(subparsers) + print_subcommand_description(self.parser, subparsers) + def parse_args(self) -> argparse.Namespace: return self.parser.parse_args() diff --git a/llama_stack/cli/model/model.py b/llama_stack/cli/model/model.py index 2f4065b83..ec1fc8cf1 100644 --- a/llama_stack/cli/model/model.py +++ b/llama_stack/cli/model/model.py @@ -13,6 +13,7 @@ from llama_stack.cli.model.prompt_format import ModelPromptFormat 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): @@ -24,6 +25,7 @@ class ModelParser(Subcommand): "model", prog="llama model", description="Work with llama models", + formatter_class=argparse.RawTextHelpFormatter, ) self.parser.set_defaults(func=lambda args: self.parser.print_help()) @@ -37,3 +39,5 @@ class ModelParser(Subcommand): ModelDescribe.create(subparsers) ModelVerifyDownload.create(subparsers) ModelRemove.create(subparsers) + + print_subcommand_description(self.parser, subparsers) diff --git a/llama_stack/cli/stack/stack.py b/llama_stack/cli/stack/stack.py index 431f7b98e..7b6215ef4 100644 --- a/llama_stack/cli/stack/stack.py +++ b/llama_stack/cli/stack/stack.py @@ -8,6 +8,7 @@ import argparse 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 @@ -22,6 +23,7 @@ class StackParser(Subcommand): "stack", prog="llama stack", description="Operations for the Llama Stack / Distributions", + formatter_class=argparse.RawTextHelpFormatter, ) self.parser.add_argument( @@ -39,3 +41,5 @@ class StackParser(Subcommand): StackListApis.create(subparsers) StackListProviders.create(subparsers) StackRun.create(subparsers) + + print_subcommand_description(self.parser, subparsers) diff --git a/llama_stack/cli/stack/utils.py b/llama_stack/cli/stack/utils.py new file mode 100644 index 000000000..1e83a5cc8 --- /dev/null +++ b/llama_stack/cli/stack/utils.py @@ -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