Elffuss BraidHub

kikocis/llama-stack public

efac2a2f572e · 1.5 KiBRawPermalink
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2# All rights reserved.
3#
4# This source code is licensed under the terms described in the LICENSE file in
5# the root directory of this source tree.
6
7import argparse
8
9from .download import Download
10from .model import ModelParser
11from .stack import StackParser
12
13
14class LlamaCLIParser:
15 """Defines CLI parser for Llama CLI"""
16
17 def __init__(self):
18 self.parser = argparse.ArgumentParser(
19 prog="llama",
20 description="Welcome to the Llama CLI",
21 add_help=True,
22 )
23
24 # Default command is to print help
25 self.parser.set_defaults(func=lambda args: self.parser.print_help())
26
27 subparsers = self.parser.add_subparsers(title="subcommands")
28
29 # Add sub-commands
30 Download.create(subparsers)
31 ModelParser.create(subparsers)
32 StackParser.create(subparsers)
33
34 # Import sub-commands from agentic_system if they exist
35 try:
36 from llama_agentic_system.cli.subcommand_modules import SUBCOMMAND_MODULES
37
38 for module in SUBCOMMAND_MODULES:
39 module.create(subparsers)
40
41 except ImportError:
42 pass
43
44 def parse_args(self) -> argparse.Namespace:
45 return self.parser.parse_args()
46
47 def run(self, args: argparse.Namespace) -> None:
48 args.func(args)
49
50
51def main():
52 parser = LlamaCLIParser()
53 args = parser.parse_args()
54 parser.run(args)
55
56
57if __name__ == "__main__":
58 main()