feat(cli): ls libraries

This commit is contained in:
arkohut 2024-06-02 00:25:02 +08:00
parent dd3b32821d
commit 8caa5c5a7e
4 changed files with 9 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import typer import typer
import httpx import httpx
from memos.server import run_server from memos.server import run_server
from tabulate import tabulate
app = typer.Typer() app = typer.Typer()
@ -12,8 +13,12 @@ def serve():
def ls(): def ls():
response = httpx.get("http://localhost:8080/libraries") response = httpx.get("http://localhost:8080/libraries")
libraries = response.json() libraries = response.json()
table = []
for library in libraries: for library in libraries:
print(library['name']) table.append([library['id'], library['name'], "\n".join(folder['path'] for folder in library['folders'])])
print(tabulate(table, headers=["ID", "Name", "Folders"]))
if __name__ == "__main__": if __name__ == "__main__":
app() app()

View File

@ -131,5 +131,5 @@ class LibraryPluginModel(Base):
# Create the database engine with the path from config # Create the database engine with the path from config
engine = create_engine(f"sqlite:///{get_database_path()}", echo=True) engine = create_engine(f"sqlite:///{get_database_path()}")
Base.metadata.create_all(engine) Base.metadata.create_all(engine)

View File

@ -1,4 +1,4 @@
from pydantic import BaseModel, ConfigDict, DirectoryPath, HttpUrl, field_validator from pydantic import BaseModel, ConfigDict, DirectoryPath, HttpUrl
from typing import List from typing import List
from datetime import datetime from datetime import datetime
from enum import Enum from enum import Enum

View File

@ -4,3 +4,4 @@ httpx
pydantic pydantic
sqlalchemy sqlalchemy
typer typer
tabulate