Source-verified agent skills for Go: Cobra command-line interfaces, Viper configuration, and Wails desktop apps, each backed by tested examples.
99
100%
Does it follow best practices?
Impact
99%
1.02xAverage score across 18 eval scenarios
Passed
No findings from the security scan
Cobra adds a default completion command when the root executes. With
subcommands it is listed in help. A root without subcommands still intercepts
the word completion as its first argument, so its RunE never receives that
value. Control this with root.CompletionOptions.DisableDefaultCmd and
HiddenDefaultCmd, and check existing behavior before adding another
generator. It supports Bash, Zsh, Fish, and PowerShell; write scripts on
explicit request rather than silently editing shell startup files.
ValidArgs; pair with cobra.OnlyValidArgs if
invalid values must also be rejected. Completion is not validation.ValidArgsFunction.RegisterFlagCompletionFunc, after the flag exists. Check its
returned error. The command handler must still validate values independently.cobra.ShellCompDirectiveNoFileComp for repo IDs, names, and tags so the
shell does not add unrelated filesystem suggestions. For path flags, use
MarkFlagFilename(name, "yaml", "yml") or MarkFlagDirname(name); these set
the ShellCompDirectiveFilterFileExt and ShellCompDirectiveFilterDirs
directives, which are constants, not functions.root.SetArgs([]string{"__complete", "list", "--tag", "g"}), using a new tree and captured output. Stdout holds
one candidate per line, then :<directive>. Check the candidates and
directive; do not hardcode incidental help wording. The --tag completion in
commands.md has such a test.PersistentPreRunE runs for completion <shell> and every
__complete request. Keep config loading out of it, or completion fails
wherever the config is missing or invalid.Documentation generation is in github.com/spf13/cobra/doc, e.g.
doc.GenMarkdownTree(root, outputDir) and doc.GenManTree(root, header, outputDir),
where header is a *doc.GenManHeader with the title, section, and date.
Generate from the same command constructors used by the binary. For
reproducible output, set root.DisableAutoGenTag = true to drop the
"Auto generated by spf13/cobra" footer and its date, give the man header a fixed
Date and a Source, and compare output intentionally.
When a flag or hook behaves unexpectedly:
ExecuteC/ExecuteContextC.Changed, parsing boundaries (--), positional arguments, and the
difference between StringArray and StringSlice.Pinned sources: completion guide, completion implementation, documentation generators.