cli

drive the vault from a terminal

There are no hand-written command wrappers here. cmd turns any Vault method into a plain function — self and **kw stripped — and fastcore’s anno_parser reads the docments off it, so every flag, default and help string in the CLI is the source of the method it calls. Adding a method to CMDS is the whole of adding a command.


source

cmd

def cmd(
    name:str, vault_fn:_lru_cache_wrapper=vault
):

A Vault method as a plain function: self and **kw dropped, docments kept.

__delwrap__ is what makes the second half work — docments walks it to find the comments in the original source, so anno_parser and MCP both get help text for free.


source

vault

def vault(
    path:str=None
)->Vault:

The vault every command shares: $VISHALAKSHI_VAULT, else the default path.


source

main

def main():

Entry point for the vishalakshi command. vishalakshi <cmd> --help documents any command.


source

show

def show(
    r
):

Print a result: an answer as prose with its citations, anything else as JSON.


source

jsonable

def jsonable(
    o
):

json.dumps fallback: L and friends become lists, numpy scalars numbers, the rest strings.

Try it

p = anno_parser(cmd('find'), prog='vishalakshi find')
p.print_help()
args = p.parse_args(['late chunking', '--limit', '3', '--kind', 'note,web']).__dict__
test_eq(args['q'], 'late chunking'); test_eq(args['limit'], 3); test_eq(args['kind'], 'note,web')
test_eq(sorted(set(CMDS) - {m for m in dir(Vault) if not m.startswith('_')}), [])   # every command is a real method
test_eq(json.loads(json.dumps(L(['a', 'b']), default=jsonable)), ['a', 'b'])        # `L` is not a list; JSON needs telling