daedalus 0.3.0: argparse CLI + argcomplete shell completion, script-arg delegation
- cli.py rewritten on argparse (build_parser, REMAINDER pass-through: everything after the script name still belongs to the script); help/errors are argparse-rendered, exit code 2 kept for all daedalus errors - completions.py (new): category-aware candidates for argcomplete - script names + unused labels narrowed by typed labels (daedalus test h<TAB> -> hello); --path completes scripts; after a completed script name daedalus offers nothing of its own and delegates .py scripts to their own parser via the run_python_script child with a rewritten COMP_LINE (daedalus hello -<TAB> -> hello's -h --help); SPEC 6.9 documents the autocomplete(parser) opt-in - SPEC: item 1.5 reuse-first third-party policy, 3.8/3.10/3.11 argparse texts, 3.13 completion catalog, 6.9 script opt-in, 9.6 argcomplete dependency - argcomplete>=3.3 as runtime dep (guarded import: CLI runs without it); register-python-argcomplete line for ~/.bashrc; PYTHON_ARGCOMPLETE_OK marker in bin/daedalus; README/INSTALL/CHANGELOG updated; hello opts in - tests: argparse CLI suites, completer units, end-to-end argcomplete probes through the bash fd-8 protocol and the delegation exec chain (autotest green, coverage 97%) Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
+42
@@ -6,6 +6,7 @@ bundles every registered one and works from any directory.
|
||||
|
||||
- [Install](#install)
|
||||
- [Usage](#usage)
|
||||
- [Tab completion](#tab-completion)
|
||||
- [Add a script](#add-a-script)
|
||||
- [Development](#development)
|
||||
|
||||
@@ -119,6 +120,47 @@ Python scripts run through `daedalus/run_python_script.py`: they get
|
||||
shared code), file and console logging to `~/.daedalus/debug.log`, and
|
||||
their `sys.argv` and exit code passed through unchanged.
|
||||
|
||||
## Tab completion
|
||||
|
||||
Completion is built with [argcomplete](https://github.com/kislyuk/argcomplete);
|
||||
it completes script names, category labels, and options — including
|
||||
script names after category labels.
|
||||
|
||||
Bash: register once per shell, e.g. in `~/.bashrc` (the program on
|
||||
`PATH` must be able to `import argcomplete`):
|
||||
|
||||
```bash
|
||||
eval "$(register-python-argcomplete daedalus)"
|
||||
```
|
||||
|
||||
zsh:
|
||||
|
||||
```bash
|
||||
autoload -U bashcompinit && bashcompinit
|
||||
eval "$(register-python-argcomplete daedalus)"
|
||||
```
|
||||
|
||||
Try it in a new shell:
|
||||
|
||||
```bash
|
||||
daedalus hel<TAB> # completes hello
|
||||
daedalus test <TAB><TAB> # lists the scripts (and labels) for the prefix
|
||||
daedalus --<TAB> # completes the daedalus options
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- `register-python-argcomplete` ships with the argcomplete package; it
|
||||
comes with the pipx/pip install (a daedalus dependency since 0.3.0)
|
||||
or with your system package (Debian: `python3-argcomplete`).
|
||||
- Arguments after the script name belong to the script: a Python script
|
||||
that calls `argcomplete.autocomplete(parser)` (SPEC item 6.9) completes
|
||||
its own arguments — `daedalus hello -<TAB>` offers hello's `-h`,
|
||||
`--help`. Otherwise the shell offers file names there.
|
||||
- A checkout run through `bin/daedalus` completes when the `python3`
|
||||
it runs can `import argcomplete` and the marker comment stays in the
|
||||
launcher (SPEC item 3.13.7).
|
||||
|
||||
## Add a script
|
||||
|
||||
- Put the file in the folder for its type:
|
||||
|
||||
Reference in New Issue
Block a user