diff --git a/sentential/cli/store.py b/sentential/cli/store.py index 5d54b70..efd8ab6 100644 --- a/sentential/cli/store.py +++ b/sentential/cli/store.py @@ -1,35 +1,42 @@ import typer -from typing import List from rich import print +from typing import List, Tuple, Callable +from sentential.lib.store import Store from sentential.lib.ontology import Ontology store = typer.Typer() -@store.callback() -def namespace(ctx: typer.Context): - ctx.obj = getattr(Ontology(), str(ctx.command.name)) +def _from_context(ctx: typer.Context) -> Tuple[Store, Callable]: + zero_arg, store, method, *n_arg = ctx.command_path.split(" ") + store = getattr(Ontology(), store) + method = getattr(store, method) + return (store, method) @store.command() def ls(ctx: typer.Context): """list store""" - print(getattr(ctx.obj, str(ctx.command.name))()) + store, method = _from_context(ctx) + print(method()) @store.command() def set(ctx: typer.Context, key: str, value: str): """set KEY VALUE in store""" - print(getattr(ctx.obj, str(ctx.command.name))(key, value)) + store, method = _from_context(ctx) + print(method(key, value)) @store.command() def rm(ctx: typer.Context, key: str): """delete KEY in store""" - print(getattr(ctx.obj, str(ctx.command.name))(key)) + store, method = _from_context(ctx) + print(method(key)) @store.command() def clear(ctx: typer.Context): """delete all in store""" - print(getattr(ctx.obj, str(ctx.command.name))()) + store, method = _from_context(ctx) + print(method())