cobracmd: standard completion and exit codes for cobra programs; bash install line via eval
New module yetano.dev/yetano/core/cobracmd (own go.mod, cobra stays out of the main module): Completion replaces cobra's default completion command, which exits 0 for an unknown shell, with one that accepts only bash|zsh|fish|powershell (exit 2 otherwise); Execute maps cobra's usage errors to exit 2, other errors to 1. completion: the bash script's install line is eval "$(prog completion bash)" -- bash 3.2 on macOS cannot source a process substitution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fa52990e3e
commit
5288c4ce74
6 files changed
+317
-1
No files matched your search
@@ -29,6 +29,7 @@ yetano.dev/yetano/core/doctor
|
||||
yetano.dev/yetano/core/configcmd
|
||||
yetano.dev/yetano/core/version
|
||||
yetano.dev/yetano/core/secretref
|
||||
yetano.dev/yetano/core/cobracmd (separate module)
|
||||
|
||||
yetano.dev/yetano/core/gui (own module, tags gui/vX.Y.Z)
|
||||
yetano.dev/yetano/core/gui/assets
|
||||
@@ -373,6 +374,17 @@ options of other programs), and `create`/`upgrade` keep working on the
|
||||
program's own file. `KnownKey(schema, "a.b[0].c")` tells whether a
|
||||
dotted key is an option of a config struct.
|
||||
|
||||
## core/cobracmd: cobra programs (separate module)
|
||||
|
||||
`yetano.dev/yetano/core/cobracmd` (own `go.mod`, tags `cobracmd/vX.Y.Z`,
|
||||
so the main module stays free of cobra) fixes the two places where cobra
|
||||
behaves differently from the standard: `cobracmd.Completion(root)`
|
||||
replaces cobra's default `completion` command with one that takes exactly
|
||||
`bash|zsh|fish|powershell` (cobra's own exits 0 for `completion tcsh`),
|
||||
and `os.Exit(cobracmd.Execute(root))` maps errors to the standard exit
|
||||
codes -- 2 for usage errors (unknown command, flag or shell, wrong
|
||||
argument count, or an error wrapped with `cobracmd.Usage`), 1 otherwise.
|
||||
|
||||
## core/version: "<program> version [--json]"
|
||||
|
||||
The values stay in each program's `internal/version` (stamped with
|
||||
|
||||
Reference in new issue
Block a user