feat: add list built stacks

Signed-off-by: reidliu <reid201711@gmail.com>
This commit is contained in:
reidliu 2025-03-06 07:20:33 +08:00
parent 6cf79437b3
commit 1806de366f
2 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,50 @@
# 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.
import argparse
import os
import time
from llama_stack.cli.subcommand import Subcommand
from llama_stack.distribution.utils.config_dirs import DISTRIBS_BASE_DIR
class StackList(Subcommand):
def __init__(self, subparsers: argparse._SubParsersAction):
super().__init__()
self.parser = subparsers.add_parser(
"list",
prog="llama stack list",
description="List the built stacks",
formatter_class=argparse.RawTextHelpFormatter,
)
self._add_arguments()
self.parser.set_defaults(func=self._run_stack_list_cmd)
def _add_arguments(self):
pass
def _run_stack_list_cmd(self, args: argparse.Namespace) -> None:
from llama_stack.cli.table import print_table
headers = ["Stack(s)", "Modified Time"]
rows = []
for stack in os.listdir(DISTRIBS_BASE_DIR):
abs_path = os.path.join(DISTRIBS_BASE_DIR, stack)
modified_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(os.path.getmtime(abs_path)))
rows.append(
[
stack,
modified_time,
]
)
print_table(
rows,
headers,
separate_rows=True,
)

View file

@ -11,6 +11,7 @@ from llama_stack.cli.stack.utils import print_subcommand_description
from llama_stack.cli.subcommand import Subcommand
from .build import StackBuild
from .list import StackList
from .list_apis import StackListApis
from .list_providers import StackListProviders
from .run import StackRun
@ -38,6 +39,7 @@ class StackParser(Subcommand):
# Add sub-commands
StackBuild.create(subparsers)
StackList.create(subparsers)
StackListApis.create(subparsers)
StackListProviders.create(subparsers)
StackRun.create(subparsers)