* main: (39 commits)
Add '--version' flag to Help output (#1707)
Expose ValidateRequiredFlags and ValidateFlagGroups (#1760)
Document option to hide the default completion cmd (#1779)
ci: add workflow_dispatch (#1387)
add missing license headers (#1809)
ci: use action/setup-go's cache (#1783)
Adjustments to documentation (#1656)
Rename Powershell completion tests (#1803)
Support for case-insensitive command names (#1802)
Deprecate ExactValidArgs() and test combinations of args validators (#1643)
Use correct stale action `exempt-` yaml keys (#1800)
With go 1.18, we must use go install for a binary (#1726)
Clarify SetContext documentation (#1748)
ci: test on Golang 1.19 (#1782)
fix: show flags that shadow parent persistent flag in child help (#1776)
Update gopkg.in/yaml.v2 to gopkg.in/yaml.v3 (#1766)
fix(bash-v2): activeHelp length check syntax (#1762)
fix: correct command path in see_also for YAML doc (#1771)
build(deps): bump github.com/inconshreveable/mousetrap (#1774)
docs: add zitadel to the list (#1772)
...
Add a global `EnableCaseInsensitive` variable to allow
case-insensitive command names.
The variable supports commands names and aliases globally.
Resolves#1382
The format "go install github.com/kyoh86/richgo@latest" will work with
go 1.16 and higher. It will not work with go 1.15. However, since
installing "richgo" is only required for people who want to run the go
tests for the Cobra project itself, I feel it is ok to require go 1.16
or higher in this case.
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
* ci: test on Golang 1.19
* ci: run golangci-lint on golang 1.19
* Adds `check-latest` for setup-go action v3
* ci/golangci-lint: use latest version available in setup-go's manifest
Signed-off-by: John McBride <jpmmcbride@gmail.com>
Signed-off-by: umarcor <unai.martinezcorral@ehu.eus>
Co-authored-by: John McBride <jpmmcbride@gmail.com>
This fixes a bug where a child flag that shadows (has the same
name as) a parent persistent flag would not be shown in the
child command's help output and the parent flag would be shown
instead under the global flags section.
This change makes the help output consistent with the
observed behavior during execution, where the child flag is
the one that is actually used.
```shell
$ set -u
$ foo=()
$ echo ${#foo}
bash: foo: unbound variable
echo ${#foo[*]}
0
```
The above shows that an empty array needs the suffix `[*]` when checking its length, or else it is considered unbound.
The `see_also` section for child commands would include only the name of
the commands. This adds the whole path, similar to how it's done for the
other documentation formats.
Reaching out on behalf of KubeVirt, an add-on for Kubernetes, enabling
users to run Virtual Machines on Kubernetes pods.
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
Since go 1.13 you can wrap errors. This make it no longer possible to
compare with `==`, instead you have to compare with `errors.Is()`.
I noticed this problem because -h was no longer working after I stared
wrapping the errors in my custom FlagErrorFunc function.
Note that this is only a problem when a custom help flag is defined.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Fixes#1734
Tab characters that introduce completion descriptions weren't properly
being handled with bash v3. This change fixes that.
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
Previously the generated zsh completion script started with the line
#compdef _<command> <command>
where <command> is the command that the zsh completion script is
generated for.
This enabled completions for both <command> and _<command>, but
_<command> is the completion function itself and should not be
completed. Furthermore, attempting to autocomplete _<command> (e.g.
typing "_<command><Space><Tab>" in a zsh shell) causes zsh to hang.
This commit fixes the #compdef line to only complete <command>, not
_<command>.
Co-authored-by: Arvid Norlander <VorpalBlade@users.noreply.github.com>
Not that it'd really matter that much performancewise given the level we
are at for this case, but this change makes the short circuit roughly
twice as fast on my box as it was for the 1000 rounds done in
marckhouzam/cobra-completion-testing.
Perhaps more importantly, this makes the code arguably slightly cleaner.
If the list of candidates has no descriptions, short circuit all the
description processing logic, basically just do a `compgen -W` for the
whole list and be done with it.
We could conceivably do some optimizations like this and more when
generating the completions with `--no-descriptions` in Go code, by
omitting some parts we know won't be needed, or doing some things
differently. But doing it this way in bash, the improvements are
available also to completions generated with descriptions enabled when
they are invoked for completion cases that produce no
descriptions. The result after this for descriptionless entries seems
fast enough so it seems there's no immediate need to look into doing
that.
For legacy bash completions, similarly as commit
4f0facbcee is for bash completions v2.
As a side effect, fixes test suite with shellcheck 0.8.0 installed;
apparently the 0.7.0 that's in GitHub Actions' ubuntu-latest at the
moment does not flag the array quoting related issue that was provoked
from 0.8.0 before this change.