* Fix shellcheck
Before this change:
In - line 204:
declare -F $next_command >/dev/null && $next_command
^-- SC2086: Double quote to prevent globbing and word splitting.
--- FAIL: TestBashCompletions (0.34s)
bash_completions_test.go:138: shellcheck failed: exit status 1
* Avoid storing pointer to nil
Before this change, the new test fails with:
--- FAIL: TestSetOutput (0.00s)
command_test.go:198: expected setting output to nil to revert back to stdout, got <nil>
* bash_completions: cleanup for go vet
The gnarly block of string in the Fprint tripped up go vet and was not
easy to read.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
* test: cleanup for go vet
Looks like copy'pasta and an unused variable
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
If a user specifies a flag to a command which doesn't make sense to a
subcommand do not show subcommands as a suggestion.
This also changes things to show both 'required flags' and 'commands'
instead of only 'required flags'
The use of "declare -A flaghash" (associative array) was introduced
in PR #205, which works perfectly for Bash 4.x, but OS X insists on
shipping a very outdated Bash 3.2.x.
This patch hides the "bash: declare: -A: invalid option" error message
and allows the bash completion script to continue gracefully on
OS X, albeit without the benefit of the new feature in PR #205.
Fixes#240
Since the switch from *bytes.Buffer to io.Writer, errors can no longer
be ignored. Also makes the reuse of GenBashCompletion in
GenBashCompletionFile without a buffer treat errors properly again.
In Pull Request #178, the use of `builtin compopt` as a test condition
is inappropriate. Use `[[ $(type -t compopt) = "builtin" ]]` instead.
Also clean up formatting of the resulting bash completion script.
This slightly changes IsAvailableCommand in that a non-runnable command
with a runnable subcommand is now 'Available'
We also use IsAvailableCommand in the rest of the codebase instead of
half kinda sorta doing it incorrectly other places.
This first `cd` to a specified directory, then
lists the subdirectories therein with `_filedir -d`.
This can be used by e.g. `hugo --theme=[Tab][Tab]`, which would
give a list of subdirectories under the `themes` directory.
We were trying to call a bash function with bash stuff like @ () from a
variable. Stop that. Just call a function with an arg from a variable
instead of trying to pass around the bash.
Should fix https://github.com/spf13/cobra/pull/103