You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- [ ] **Argument groups in help** — group related options under headings (argparse add_argument_group)
525
526
- [ ] **Usage line customisation** — two approaches: (1) manual override via `.usage("...")`for git-style hand-written usage strings (e.g. `[-v | --version] [-h | --help] [-C <path>] ...`); (2) auto-expanded mode that enumerates every flag inline like argparse (good for small CLIs, noisy for large ones). Current default `[OPTIONS]` / `<COMMAND>` is the cobra/clap/click convention and is the right default.
> **Tip:** ArgMojo's [Auto-detect](#negative-number-passthrough) can handle most negative-number cases without `--`. Use `--` only when auto-detect is insufficient (e.g., a digit short option is registered without `allow_negative_numbers()`).
2037
+
2038
+
## Shell Completion
2039
+
2040
+
ArgMojo can generate **shell completion scripts** for Bash, Zsh, and Fish. These scripts enable tab-completion for your CLI's options, flags, subcommands, and choice values — with zero runtime overhead.
2041
+
2042
+
The generated scripts are **static**: they are produced once from your command tree and sourced by the user's shell. No runtime hook or callback mechanism is needed.
2043
+
2044
+
### Built-in `--completions` Flag
2045
+
2046
+
Every `Command` automatically responds to `--completions <shell>` — just like `--help` and `--version`. **No extra code is required.**
2047
+
2048
+
```mojo
2049
+
var app = Command("myapp", "My application", version="1.0.0")
# parse() handles --completions automatically — no extra code needed
2060
+
var result = app.parse()
2061
+
```
2062
+
2063
+
Users run:
2064
+
2065
+
```bash
2066
+
myapp --completions bash # prints Bash completion script and exits
2067
+
myapp --completions zsh # prints Zsh completion script and exits
2068
+
myapp --completions fish # prints Fish completion script and exits
2069
+
```
2070
+
2071
+
The `--completions` option is shown in the help output alongside `--help` and `--version`:
2072
+
2073
+
```bash
2074
+
Options:
2075
+
--help Show this help message and exit
2076
+
--version Show the version and exit
2077
+
--completions {bash,zsh,fish}
2078
+
Generate shell completion script
2079
+
```
2080
+
2081
+
### Disabling the Built-in Flag
2082
+
2083
+
If you want to use `completions` as a regular argument name — or handle completion triggering entirely on your own — call `disable_default_completions()`:
2084
+
2085
+
```mojo
2086
+
var app = Command("myapp", "My CLI")
2087
+
app.disable_default_completions() # --completions is now an unknown option
2088
+
```
2089
+
2090
+
`disable_default_completions()` removes `--completions` from the parse loop, help output, and all generated completion scripts. The `generate_completion()` method remains available for programmatic use.
2091
+
2092
+
### Customising the Trigger Name
2093
+
2094
+
By default the option is called `--completions`. Use `completions_name()` to rename it:
| Hidden arguments | No (intentional) |`.hidden()` arguments are excluded from completion |
2185
+
| Positional arguments | No (by design) | Positionals use default shell completion (file paths, etc.) |
2186
+
| Persistent (global) flags | Yes (root level) | Inherited flags appear in the root command's completions |
2187
+
2188
+
> **Note:** Negatable flags (`--color` / `--no-color`) — the `--no-X` form is **not** separately listed in completions. The base `--color` flag is completed; users type `--no-` manually. This matches the behaviour of other CLI frameworks.
0 commit comments