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:
terminarandClaude Opus 5.5 committed 2026-10-26 14:34:39 +01:00
1 parent fa52990e3e
commit 5288c4ce74
6 files changed
+317 -1

No files matched your search

+1 -1
View File
@@ -97,7 +97,7 @@ func Script(program, shell string, tree Tree) (string, error) {
var b strings.Builder
switch shell {
case "bash":
fmt.Fprintf(&b, "# %s bash completion. Install with:\n# source <(%s completion bash)\n", program, program)
fmt.Fprintf(&b, "# %s bash completion. Install with:\n# eval \"$(%s completion bash)\" (bash 3.2 on macOS cannot source <(...))\n", program, program)
fmt.Fprintf(&b, "%s() {\n local cur prefix\n cur=\"${COMP_WORDS[COMP_CWORD]}\"\n prefix=\"${COMP_WORDS[*]:1:COMP_CWORD-1}\"\n case \"$prefix\" in\n", fn)
for _, e := range entries {
fmt.Fprintf(&b, " %q) COMPREPLY=($(compgen -W %q -- \"$cur\")); return ;;\n", e.prefix, strings.Join(e.words, " "))