Repository navigation
Releases
v7.4.1: Fix PowerShell subcommand completion, fish backslash escaping, and Cobra choices
Three bug fixes: PowerShell completion after a space, fish completion scripts that embed a spec, and Cobra-generated choices blocks. These fixes are in the generated scripts and specs, so regenerate any you have already written out to pick them up.
Fixed
- (powershell) Pressing Tab after a space (for example
mise <Tab>ormise use <Tab>) now offers subcommands and arguments instead of file names (#1672, @jdx). The completer had been dropping the trailing space before passing the line to the binary. The fix is in the Rust generator, the Goargvgenerator and the checked-inusage.ps1. Thanks to @kangmingxuan for reporting and diagnosing it. - (fish) Completion scripts made with
usage generate completion fish --file spec.kdlnow keep backslashes in the embedded spec (#1659, @jdx). Before, fish's single-quote unescaping took away one level of backslashes. Acomplete ... run=command with escapes such as jq's\(.name),\tor a regex escape then turned into invalid KDL. When that happened, every completion for the binary silently returned nothing. - (cobra) Specs generated from Cobra commands with
ValidArgsnow passusage lint, for both root commands and subcommands (#1670, @jdx). The generator now writeschoice "dev"insidechoicesblocks instead of a bare"dev". Choices on flag arguments use the same format.
Full Changelog: v7.4.0...v7.4.1
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.
v7.4.0: Bash/zsh completion insertion fixes, parent-flag validation under subcommands, and `usage lint --quiet`
The shared completion subcommand can now send its script and its install report to different streams, and its install flags now declare what they do. This release also fixes how bash and zsh insert completion candidates, enforces parent flag rules after a subcommand is selected, and adds usage lint --quiet and rename_all_keys for #[derive(Config)].
Added
-
(lib)
Completion::run_split(andrun_split_infor tests) takes a second writer for the--installreport (#1629, @jdx). With it,ex completion fishprints only the script on stdout, andex completion fish --installleaves stdout empty and reports on stderr, the same asusage generate completion --install.runandrun_instill write everything to one writer.completion.run_split("ex", &mut std::io::stdout(), &mut std::io::stderr())?;
-
(lib) The shared
Completioncommand's exported spec now gives--installeffect="write"and--forceeffect="destructive"(#1627, @jdx).--forcegets the destructive label because it replaces a file usage did not generate and keeps no backup. Tools that audit or confirm command effects can now tell these flags apart from a plaincompletion <shell>, which still has no effect. -
(derive)
#[derive(Config)]takes a new struct-level option,rename_all_keys, that applies a case style to keys taken from field names (#1633, @jdx). It accepts the same values asrename_all. Explicitkey,prefix,aliasandenvvalues stay as written. A flattened group sets its ownrename_all_keysand does not inherit it from the parent. Without the option, keys don't change.#[derive(usage_rs::Config)] #[usage(prefix = "ui", rename_all_keys = "kebab-case")] struct Ui { dialog_theme: String, // ui.dialog-theme #[usage(key = "tab_width")] explicit_key: Option<u32>, // ui.tab_width }
-
(lint)
usage lint -q/--quietprints only the findings, withoutNo issues found.or theFound N error(s)summary (#1640, @jdx). Exit codes and--format jsondon't change. This is useful when you lint many specs in a loop:for f in scripts/*; do "$f" --usage-spec | usage lint -q -W -; done
Fixed
- (complete) Fixed how bash and zsh insert completion candidates in the scripts generated by usage-argv (#1644, @jdx).
- bash: completing
--shell=banow gives--shell=bashinstead of--shell=--shell=bash. - Trailing spaces: in bash and zsh, only finished candidates get a trailing space. Candidates ending in
@,:,/or=(such asnode@orsub/) are left open so you can keep typing.
- bash: completing
- (complete) With
default_subcommand_on_empty #true, completion at the root now offers the root's own subcommands and flags again instead of the default command's (#1631, @jdx). Parsing, help andusage explainstill select the default command. - (parse) A parent command's non-global flags now have their
required,requiresandconflictsrules enforced after a subcommand is selected, as the docs describe (#1635, @jdx). Before,x --a --c --d subpassed even thoughx --a --c --dfailed.subcommand_negates_reqsstill relaxesrequiredandrequires, and a flag that a subcommand redeclares follows the subcommand's definition. Behavior change: invocations that skipped a required parent flag or broke a parent'srequires/conflictsrule now fail. - (parse) On commands that have subcommands, usage-lib now handles the
helpsubcommand that the help page lists (x help,x help a,x a help) instead of failing withunexpected word: help(#1639, @jdx). On a leaf command,helpis now an ordinary word. A command's ownhelpsubcommand anddisable_help_subcommandstill take precedence. Behavior change: if a positional has strictchoicesthat don't includehelp, the wordhelpis now rejected as an invalid choice instead of showing help. - (cli)
usage bashand the other script runners now use the script's spec to decide whether-h/--helpasks for help (#1637, @jdx). A script withdisable_helpand its own-hflag, or a flag withallow_hyphen_valuesthat receives-has its value, now runs instead of printing help. Arguments after--are also handled correctly. - (cli)
usage bash,usage execand delegated completions now report an error if the shell or interpreter can't be started underqemu-userand similar platforms (#1653, @jdx). Before, they exited 127 with nothing on stderr. One side effect: an executable interpreter file with no shebang line now runs through/bin/shinstead of failing with "Exec format error".
Documentation
- Added
kongusage, a usage spec generator for Kong CLIs in Go, to the integrations page (#1643, @jdx).
Full Changelog: v7.3.0...v7.4.0
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.
v7.3.0: Shared `completion` subcommand for usage-rs CLIs
usage-rs now ships a ready-made completion subcommand. Every CLI built on it can mount the command, so they all print and install shell completions the same way.
Added
-
(lib) New
usage_rs::completion::Completionsubcommand, available with thecompletionsfeature (#1624, @jdx). Until now each tool wrote its owncompletioncommand: some had--install, while others printed a script for the user to redirect by hand. You can now mount the shared command instead:use usage_rs::completion::Completion; #[derive(Subcommands)] enum Commands { /// Generate shell completions Completion(Completion), } // in the run function: completion.run("ex", &mut std::io::stdout())?;
Any tool that mounts it gets these commands:
ex completion fish # print the script, e.g. `ex completion fish | source` ex completion fish --install # write it where fish looks for it ex completion fish --install --force # also replace a file usage did not generate- Shells:
bash,elvish,fish,nu/nushell,powershell/pwshandzshare accepted. Any other shell name fails to parse. - Flags:
--forcerequires--install. - Scripts: The scripts are the short callback scripts. They contain no spec and don't need the
usagebinary. On every Tab they ask the installed tool for candidates, so they stay correct when the tool is upgraded. - Installing:
--installnever edits a startup file. If a shell needs a line added once, the command prints that line after the install path. - Errors:
Completion::runreturnsError::InstallorError::Output. A closed pipe (for exampleex completion zsh | head) is not treated as an error. - Testing:
Completion::run_intakes an explicitEnv, so tests can install without touching the real home directory.
The Rust completions guide (
docs/rust/completions.md) now usesCompletionin place of the hand-written example. - Shells:
Full Changelog: v7.2.0...v7.3.0
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.
v7.2.0: Refuse unknown environment variables under an application prefix
A CLI can now claim an environment variable prefix. Any variable under that prefix that the spec doesn't declare then makes the parse fail, which catches typos and stale names in deployment config. This release also lets derive flags declare their own settings, makes flags inside clauses set their settings, and adds --help/--version to tab completion.
Added
-
(spec) New opt-in
unknown_envnode (#1609, @jdx). When it's set, a parse fails if the environment holds any variable under the prefix that nothing in the spec reads, and the error lists every such variable at once. Without the node, nothing changes.unknown_env prefix="MOQ_" { allow "MOQ_VAAPI_DEVICE" "MOQ_V4L2_ENCODER" } flag "--port <port>" env="MOQ_PORT" cmd "serve" { flag "--tls-cert <path>" env="MOQ_TLS_CERT" deprecated_env="MOQ_CERT" }
Rust derive CLIs declare it on the root struct:
#[usage(bin = "moq", unknown_env(prefix = "MOQ_", allow("MOQ_VAAPI_DEVICE")))]. WithMOQ_PROTandMOQ_TSLset, a derived CLI exits 2:error: unknown environment variables under 'MOQ_': MOQ_PROT MOQ_TSLA variable counts as known if anything in the command tree declares it, not only the command that ran. That covers
env,env_fallbackanddeprecated_envon any flag or argument, including those in subcommands, flattened groups and clauses. It also covers variables read byconfigproperties and names inallow. Other details:- The prefix only limits which variables are checked. It is never used to build a variable name, so this is not clap's
env_prefix. - Deprecated names still produce a deprecation warning rather than an error.
--helpand--versionare answered before the check runs.- On Windows, names are compared case-insensitively.
In usage-lib,
Parserchecks the map passed toParser::with_envif there is one, and the process environment otherwise. It reports aUsageErr::UnknownEnv. - The prefix only limits which variables are checked. It is never used to build a variable name, so this is not clap's
-
(go) Parsers from
usage generate gonow enforceunknown_envtoo (#1612, @jdx). Before this, generated Go ignored the node. The check runs before required flags and arguments are checked, and it reports offenders in sorted order:error: unknown environment variables under `MOQ_`: `MOQ_PROT`, `MOQ_TSL`The Go generator can't see what variables a mounted command declares, so
usage generate gofails on a spec that has bothunknown_envand amount.go/argvaddsUnknownEnv,RefuseUnknownEnv,EnvNamesand the error codeCodeUnknownEnv. -
(derive) A field with
setting = "key"now declares that setting on its own, so you no longer need a matching#[derive(Config)]field (#1610, @jdx). The registry entry takes its type from the field's type and its environment names fromenv/env_fallback/deprecated_env. List splitting comes fromdelimiter(,or:), help comes from the doc comment, and the flags are every flag bound to the key. The rootClinow exposesSETTINGS_PROPSandSETTINGS_REGISTRY, and its spec gets aconfigblock even when there is noconfig = Type.#[derive(usage_rs::Args)] struct ListenTls { /// Load the given certificate from disk. #[usage(long = "listen-tls-cert", env = "EX_LISTEN_TLS_CERT", delimiter = ',', setting = "listen.tls.cert")] cert: Vec<std::path::PathBuf>, }
If several subcommands bind the same key, they must agree on field type, environment names and delimiter. Otherwise it's a compile error. Existing CLIs don't need to change, because a key declared on the
configstruct takes precedence over the flag. Settings that need a default,merge,scopeorchoicesstill have to beConfigfields. Settings declared only by a flag are always optional and have no default.
Fixed
- (complete) Tab completion now offers
-h/--help, and-V/--versionwhere the parser accepts them (#1605, @jdx). Before this fix, CLIs compiled from the derive andusageitself never offered these flags. This applies to both the derive andusage complete-word. A spelling that a declared flag already uses (hidden flags included) is not offered twice, anddisable_help_flag/disable_version_flagare respected. Also, merging a mounted spec no longer clearsdisable_help_flag,disable_help_subcommandordisable_version_flagon the host command. For example,mise runno longer gets--helpback from the mounted root. - (derive) A flag with
setting = "key"inside a#[usage(clause)]element now sets its setting, the same way a flag in a flattened group does (#1611, @jdx). When several clause items give the same setting, list settings collect every entry in order and other settings keep the last value. A root whose only bound flags are in clauses can now use#[usage(settings)]. Before this fix, that failed to compile.
Full Changelog: v7.1.5...v7.2.0
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.
v7.1.5: Reject relationship properties that name several targets
Specs that list several flags in one relationship property, or repeat the property, now fail to load with an error. Before this release, usage accepted them but enforced nothing.
Fixed
-
(spec) A relationship property such as
conflicts="--b --c"is now rejected when the spec loads (#1599, @jdx). Previously,--b --cwas read as one selector that matched no flag, so--a --band--a --cboth parsed without error. Repeating the property (conflicts="--b" conflicts="--c") also loaded, but only the last value was kept. Both forms now produce an error:conflicts takes one flag or argument per property, but "--b --c" has several; write them as a child node instead: conflicts "--a" "--b" conflicts is given more than once; the second would replace the first, so write several as a child node instead: conflicts "--a" "--b"This check applies to
conflicts,overrides,requires,required_if,required_unlessandrequired_unless_allon flags, and to the same properties exceptoverrideson positional args. A value is refused only if it has more than one word and at least one starts with a dash. Values likeconflicts="input file"still refer to a positional named[input file].Upgrading: These specs were never enforcing their relationships, so they now need to be rewritten in the child-node form. That form already worked and has not changed:
flag "--a" { conflicts "--b" "--c" }
The flag reference (
docs/spec/reference/flag.md) now covers the child-node form and these load-time errors.
Full Changelog: v7.1.4...v7.1.5
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.
v7.1.4: Mounted scripts tolerate rejected env values; Cobra exporter quotes boolean and numeric defaults
A mount run= that reads another usage script's spec no longer fails when an environment variable holds a value that script rejects, and the Cobra exporter now writes specs that usage lint accepts.
Fixed
-
(lib) A
mount run=that gets its spec from another usage-shebang script now works even when the environment holds a value that one of that script's env-bound flags rejects (#1591, @jdx). For example, if the child declaresflag "--mode <m>" env="X_MODE" { choices "a" "b" }, thenX_MODE=zzz ./parent subused to fail withInvalid choice for option mode: zzz(exit 181), and completion failed the same way. When usage runs the script itself and the parse fails, it now drops the env values the spec rejects and keeps the valid ones. If the parse still fails, the original error is reported. Running the script directly still reports invalid env values, and a bad value typed on the command line is still an error.When a mount does fail, the error now names the command being resolved:
could not read the commands mounted under `sub`: exited with code 1 sh -c ./child2This message comes from
usage-lib, so CLIs built on it show the same wording. Script exit codes have not changed, and they are now documented indocs/cli/scripts.md: the script's own code when it runs,1when the command line doesn't satisfy the spec, and181when usage can't read or run something the spec depends on, such as an invalid spec or a failing mount. -
(cli) The Cobra integration now quotes flag defaults that KDL would otherwise read as non-strings (#1595, @jdx). Before this fix, a
Boolflag defaulting totrueor anIntflag defaulting to-1produceddefault=trueordefault=-1, andusage lintrejected the spec. Defaults such astrue,false,null,inf,-inf,nan, signed numbers (-1,+1,-0.5) and values containing[or]are now written as quoted strings. Plain values such asjsonare still written without quotes.
Full Changelog: v7.1.3...v7.1.4
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.
v7.1.3: Order subcommand help sections by display_order
display_order on a subcommand now sets where its whole help section appears, not just its position within the section. Before this, the ungrouped Commands: section, which holds the built-in help, always came first.
Fixed
-
(cli) CLIs that group subcommands with
help_headingcan now put the defaultCommands:section after their named sections (#1583, @jdx). Each section is placed according to the lowestdisplay_orderamong its commands. A command without adisplay_ordercounts as999, so the built-inhelpnever moves its section forward. Sections with the same value keep their current order.usage-argvruntime help and theusage-libreference renderer both follow this rule.enum Cmds { #[usage(display_order = 99)] Completion(NoArgs), #[usage(help_heading = "Source", display_order = 1)] Fmt(NoArgs), #[usage(help_heading = "Dependencies", display_order = 2)] Fetch(NoArgs), }
Help used to list
Commands:(completion, help), thenSource:, thenDependencies:. It now listsSource:,Dependencies:, thenCommands:.If none of your commands set
display_order, help looks the same as before. If you setdisplay_orderon grouped commands but not on ungrouped ones, the ungrouped section now appears last.
Full Changelog: v7.1.2...v7.1.3
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.
v7.1.2: Completion scripts treat candidates as plain text; mounted commands stop inheriting top-level completers
Generated bash, zsh and fish completion scripts no longer expand completion candidates or file extensions as shell code. Mounted commands also stop picking up the mounting spec's top-level completers. The first fix matters for tools like mise, where candidates can come from project files. Regenerate any completion files you've installed to get the script fixes.
Fixed
- (complete) Completion candidates and extension filters are now handled as plain text in every shell (#1581, @jdx):
- bash:
usage generate completion bashused to pass candidates throughcompgen -W, which expands them as shell input. Arun=completer that printed$(touch pwned)ran that command when you pressed Tab, and a*candidate turned into the files in the current directory. Thecompletion-inithandler had the same globbing problem. Both now read one candidate per line without expanding it, so a candidate that contains a space stays one entry instead of splitting in two. - zsh: extension names were inserted directly into the
_files -gpattern, and zsh runs glob qualifiers as code. The pattern is now built only from plain extension names (letters, digits,_ . + -). If no usable names are left, completion falls back to unfiltered_files. This also fixes a single extension, which produced*.(toml)and matched nothing. It now produces*.toml. - fish: extensions are matched as a literal suffix, so a
*or?in an extension no longer matches extra files.
- bash:
Changed
- (complete) A command brought in by
mountnow uses only the completers it declares itself, in its owncompletenodes or inside itsargnodes (#1581, @jdx). Before, a mounted argument that shared a name with a top-level completer (for example<tool>) used the mounting spec's completer, even when the mounted command declared its own. If you type one of the mounting CLI's flags inside a mounted command, its value still completes the same way it does outside the mount. Specs without mounts are unaffected. If a mounted command relied on a top-level completer, declare it in the spec that the mount emits instead, for example withcomplete "tool" run="..."inside thecmd.
Full Changelog: v7.1.1...v7.1.2
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.
v7.1.1: Fix nushell 0.116 deprecation warning in generated completions
Nushell completion scripts generated by usage-argv and the Go runtime no longer print a deprecation warning on nushell 0.116.
Fixed
- (complete) Nushell 0.116 deprecated external completers that take a positional
spansargument, so the generated script printed anu::shell::deprecatedwarning every time it completed (#1570, @jdx). The completer now uses the{|place|}signature. On 0.116 it reads the tokens from$place.command, and on older nushell releases, which pass the token list directly, it uses that list. If you already had an external completer installed, it still gets called, and it receives the input in the format it expects: the token list for completers written withspans, the original input for everything else. If you saved the script to a file, regenerate it to pick up the fix.
Full Changelog: v7.1.0...v7.1.1
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.
v7.1.0: Effect v4 CLI exporter and bash completion escaping
This release adds usage-spec-effect, a new npm package that turns Effect v4 effect/cli command trees into usage specs. It also fixes bash completions from usage-argv, which could pass the command a different value than the one offered when a candidate contained quotes, spaces or other shell syntax.
Added
-
(spec)
usage-spec-effectexports a usage spec from an Effect v4effect/clicommand tree (#1564, @jdx). Effect still parses and runs the CLI, and the spec drives shell completions, markdown docs and man pages. It requireseffect4.x.npm install usage-spec-effect
import { generate } from "usage-spec-effect"; if (process.argv.includes("--usage-spec")) { process.stdout.write(generate(app, { version: "1.0.0" })); process.exit(0); }
mycli --usage-spec | usage generate completion bash mycli --file -The exporter handles nested subcommands, aliases, unlisted commands, examples, shared flags (exported as
global), flag aliases, boolean and valued flags, choices, defaults, and optional and variadic args. Some constructs can only be exported approximately:orElsealternatives, file, redacted and key-value types (exported as strings), non-primitive defaults, and flags with an optional value.generateWithReportreturns these in anunsupportedlist so they aren't dropped without notice. Effect's publicCommandtype doesn't expose flags or arguments, so the exporter reads the command's runtime config. If a future Effect release changes that shape,generatethrows an error that names the command. See the Effect integration guide.
Fixed
- (bash)
usage-argvandusage-dynamicnow escape bash completion candidates so the command gets the value that was offered (#1566, @jdx). Before this fix, Readline put candidates on the line unescaped, so a candidate liketasks."hello.sh"reached the command astasks.hello.sh, andit's hereleft an unclosed quote on the line. Candidates are now backslash-escaped. When a quote is already open in the word (',"or$'), each candidate is escaped for that quote style instead. Path completions still use Readline's own filename quoting, and zsh and fish were already correct. Hosts handling__complete_word__should callrender_request(&answer, &request)instead ofrender(&answer, shell)so the open-quote state is used.App::completion_requestinusage-dynamicalready does this. The script-based bash completions behindusage complete-wordare unchanged, sincecompgen -Wcan't carry spaces or quotes in candidates.
Full Changelog: v7.0.2...v7.1.0
💚 Sponsor usage
usage is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If usage powers CLI specs, docs, or completions for a tool you maintain or use, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep usage fast, free, and independent.