mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 15:37:55 +08:00
core/cli: fix /help command usage line and help Tab completion
Use a standalone Click context so /help compact shows Usage: /compact, not nested under help. Complete /help <cmd> from the slash registry.
This commit is contained in:
@@ -60,17 +60,20 @@ def build_completer(state: ReplState) -> Callable[[str, int], str | None]:
|
||||
|
||||
|
||||
def _argument_options(state: ReplState, command: str, text: str) -> list[str]:
|
||||
if command == "/provider":
|
||||
return filter_prefix(text, sorted(state.config.providers.keys()))
|
||||
if command == "/model":
|
||||
return filter_prefix(text, sorted(state.provider.models.keys()))
|
||||
if command in {"/tools", "/stream", "/verbose"}:
|
||||
return filter_prefix(text, list(_ON_OFF_ARGS))
|
||||
if command == "/export":
|
||||
return filter_prefix(text, list(_EXPORT_ARGS))
|
||||
if command == "/resume":
|
||||
return []
|
||||
return []
|
||||
candidates: list[str] = []
|
||||
if command == "/help":
|
||||
# Second token: command name without leading slash (also accept /name).
|
||||
candidates = [n.removeprefix("/") for n in slash_commands()]
|
||||
text = text.lstrip("/")
|
||||
elif command == "/provider":
|
||||
candidates = sorted(state.config.providers.keys())
|
||||
elif command == "/model":
|
||||
candidates = sorted(state.provider.models.keys())
|
||||
elif command in {"/tools", "/stream", "/verbose"}:
|
||||
candidates = list(_ON_OFF_ARGS)
|
||||
elif command == "/export":
|
||||
candidates = list(_EXPORT_ARGS)
|
||||
return filter_prefix(text, candidates)
|
||||
|
||||
|
||||
def bind_tab_complete(readline_mod: object) -> None:
|
||||
|
||||
@@ -112,8 +112,8 @@ def help_cmd(ctx: click.Context, command: str | None) -> None:
|
||||
if cmd is None:
|
||||
click.echo(f"unknown command /{name}; try /help")
|
||||
return
|
||||
# Build a child context so get_help includes usage.
|
||||
with click.Context(cmd, info_name=name, parent=ctx) as sub:
|
||||
# Standalone context (no parent=help) so usage is "/compact …" not "help … compact".
|
||||
with click.Context(cmd, info_name=f"/{name}") as sub:
|
||||
click.echo(cmd.get_help(sub))
|
||||
return
|
||||
click.echo(slash.get_help(ctx))
|
||||
|
||||
Reference in New Issue
Block a user