Interactive shell API

Interactive CLI shell, independent of network domain logic.

nadzoring.shell.start_interactive(ctx: Context, _param: Parameter, value: bool) → None[source]

Start the shell for Click’s eager interactive option.

Parameters:
  • ctx – Root Click context.

  • _param – Interactive option definition.

  • value – Whether the option was supplied.

Command dispatch

Parse and dispatch interactive commands through the existing CLI.

class nadzoring.shell.session.ShellSession(command: Group, output: str | None = None)[source]

Interactive command dispatcher with a session-local output default.

command is the existing root Click group. output is the session default, or None to use normal CLI defaults.

__init__(command: Group, output: str | None = None) → None[source]
_defaults(command: Command) → dict[str, Any][source]

Build nested Click defaults without changing command definitions.

_dispatch(args: list[str]) → bool[source]

Handle shell built-ins or invoke Click without terminating the process.

_set_output(args: list[str]) → bool[source]

Validate output using the same choices as the CLI.

command: Group
execute(line: str) → bool[source]

Execute one shell line, returning False only for exit or quit.

Parameters:

line – Command line with shell-style quoting (not shell expansion).

Returns:

Whether the interactive session should continue.

output: str | None = None
nadzoring.shell.session.start_interactive(ctx: Context, _param: Parameter, value: bool) → None[source]

Start the shell for Click’s eager interactive option.

Parameters:
  • ctx – Root Click context.

  • _param – Interactive option definition.

  • value – Whether the option was supplied.

Click completion

Interactive completion backed by Click’s existing command tree.

nadzoring.shell.completion._output_choices(command: Command) → list[str][source]

Find output formats in the existing Click option definitions.

nadzoring.shell.completion.complete_line(command: Group, text: str) → tuple[list[str], str][source]

Return completion candidates and the partial word before the cursor.

Parameters:
  • command – Root CLI group.

  • text – Input before the cursor, including any trailing whitespace.

Returns:

Candidate values and the word they replace.

nadzoring.shell.completion.completion_items(command: Group, text: str) → tuple[list[CompletionItem], str][source]

Return Click candidates with descriptions and the replacement suffix.

Parameters:
  • command – Root CLI group.

  • text – Input before the cursor.

Returns:

Completion items and the partial value to replace.

Terminal backends

Optional terminal backends with a shared, plain-text command history.

nadzoring.shell.terminal._fallback_input(command: Group, history: list[str]) → Generator[Callable[[], str]][source]

Configure readline when available, otherwise use bare input.

nadzoring.shell.terminal._load_history(path: Path) → list[str][source]

Read history without making an inaccessible home directory fatal.

nadzoring.shell.terminal.shell_input(command: Group) → Generator[Callable[[], str]][source]

Provide a line reader with completion and persistent history.

Parameters:

command – Root Click group used for completion.

Yields:

A callable prompting for the next command line.