From 8caa5c5a7ea17b5fadf520b6d9175dc2a75c0252 Mon Sep 17 00:00:00 2001 From: arkohut <39525455+arkohut@users.noreply.github.com> Date: Sun, 2 Jun 2024 00:25:02 +0800 Subject: [PATCH] feat(cli): ls libraries --- memos/commands.py | 7 ++++++- memos/models.py | 2 +- memos/schemas.py | 2 +- requirements.txt | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/memos/commands.py b/memos/commands.py index 35c4bf8..37ac49e 100644 --- a/memos/commands.py +++ b/memos/commands.py @@ -1,6 +1,7 @@ import typer import httpx from memos.server import run_server +from tabulate import tabulate app = typer.Typer() @@ -12,8 +13,12 @@ def serve(): def ls(): response = httpx.get("http://localhost:8080/libraries") libraries = response.json() + + table = [] 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__": app() diff --git a/memos/models.py b/memos/models.py index 911e378..1da0cbd 100644 --- a/memos/models.py +++ b/memos/models.py @@ -131,5 +131,5 @@ class LibraryPluginModel(Base): # 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) diff --git a/memos/schemas.py b/memos/schemas.py index 22927a3..53ed27b 100644 --- a/memos/schemas.py +++ b/memos/schemas.py @@ -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 datetime import datetime from enum import Enum diff --git a/requirements.txt b/requirements.txt index 1da81bb..52c3046 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ httpx pydantic sqlalchemy typer +tabulate