-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixing the args issues * code automatically formatted Signed-off-by: sentential[bot] <bot@sentential> --------- Signed-off-by: sentential[bot] <bot@sentential> Co-authored-by: sentential[bot] <bot@sentential>
- Loading branch information
Showing
1 changed file
with
15 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) |