- If the flags are not bool the completion expects argument.
- You don't have to specify file extensions for file completion to
work.
- Allow multiple occurrences of flag if type is stringArray.
Need to verify that these assumption are correct :)
A very basic POC. Need to refactor to generate completion
structure before passing to the template to avoid repeated
computations.
What works:
* Real zsh completion (not built on bash)
* Basic flags (with long flag and optional shorthand)
* Basic filename completion indication (not with file extensions though)
What's missing:
* File extensions to filename completions
* Positional args
* Do we require handling only short flags?
new variable MousetrapDisplayDuration allows to modify the default
display duration of 5s, or to completely disable the timeout and wait
for the user to press the return key.
* update Example in README.md (#769)
* specify the color as the required arg (#777)
* command: fix typo in docstring of InheritedFlags (#779)
* add istio to the list of projects built with Cobra (#786)
* remove redundant 'else' (#806)
* add mattermost-server as a project built with Cobra (#824)
* update README.md (#826)
Fix the comment: consistent with others
* add uber/prototool as a project built with Cobra (#831)
* fix(ci): use go vet, update to Go 1.12, update shellcheck to v0.4.6 (#832)
* add go.mod and go.sum (#833)
* chore(travis): move 'diff' job to separate stage in Travis (#839)
* chore(travis): use language configuration list instead of explicit entries in matrix.include (#839)
* chore(travis): update shellcheck-docker to v0.6.0 (#839)
* update(README.md): separate projects by commas, instead of using a list
* chore: update viper to v1.3.2 and go-md2man to v1.0.10
* fix: convert CRLF to LF when comparing files
* use kyoh86/richgo to provide colored test outputs
* Update the Travis and CircleCI Go versions
* Adapt to new gofmt formatting
The formatting of gofmt changed slightly in go 1.11. The release
notes recommend to use a specific binary of gofmt. See
https://golang.org/doc/go1.11#gofmt
This commit adapts to the new formatting applied by gofmt and changes
the configs for travis and circleci to run gofmt only with go 1.11.
Previously if a cobra user didn't specify an explicit .Date header, the
current time would be included in all of the generated man pages each
time they were built. This causes an issue for reproducible builds,
since each re-build of a package that includes the man pages will have
different times listed in the man pages.
To fix this, add support for SOURCE_DATE_EPOCH (which is a standardised
packaging environment variable, designed to be used specifically for
this purpose[1]).
[1]: https://reproducible-builds.org/specs/source-date-epoch/
Signed-off-by: Aleksa Sarai <asarai@suse.de>
* Qualify custom bash func name
- fixes issue where multiple cobra apps using custom bash completion
would have their __custom_func collide
- support fallback to plain __custom_func to maintain compatibility
#694
* Improve tests for bash completion __custom_func
- check for the correct number of occurrences of function name
#694
As discussed in golang/go#26109, vet typecheck is enabled
in go1.11 and the command_test.go can't be compiled any
more with go1.11 due to the unread variables in the
command_test.go.
Instead of removing the unused variables, this CL reads the
variables and compares the values against the current
behavior so when the related issue is fixed, this test can
be updated accordingly.
* Prefix bash functions with root command name
Prior to this commit the autocomplete bash functions were being prefixed
with the root command name, but references to those functions from
subcommands were having the subcommands prefixed instead - causing the
function lookups to fail and error out.
For example (as observed in kubernetes/kubernetes#60517):
kubectl create -f [Tab] failed with the following message: kubectl
create -f __create_handle_filename_extension_flag: command not found
in this case the function being invoked should be __kubectl_handle_filename_extension_flag
Signed-off-by: John McCabe <john@johnmccabe.net>
* Test filename extension and subdirs_in_dir for subcommands
This commit adds two regex based tests to ensure that the handle
filename extension and handle subdirs in dir functions are prefixed by
the root command when present in subcommands.
Previously they had been prefixed incorrectly with the subcommand name.
Signed-off-by: John McCabe <john@johnmccabe.net>
* Make preamble functions unique to command
Prior to this commit the functions in the preamble had names that didn't
vary based on the command for which the bash completion was generated.
This meant that if you had two bash completions with differences in the
preamble functions then only the last loaded function would be
available.
This commit prefixes all of these functions with the name of the command
so that multiple cobra generated completion files won't clash.
Signed-off-by: John McCabe <john@johnmccabe.net>
* Fix function names in writeFlagHandler
The references to the `__handle_filename_extension_flag` and
`__handle_subdirs_in_dir_flag` functions in `writeFlagHandler` hadn't
been updated correctly in the previous commits.
Signed-off-by: John McCabe <john@johnmccabe.net>
* Pass cmd into writeFlagHandler
This commit passes the cmd pointer into the writeFlagHandler so that the
`__handle_filename_extension_flag` and `__handle_subdirs_in_dir_flag`
functions can have the `cmd.Name()` prefixed.
* Update Bash completion tests
Prefixes the tested `__handle_filename_extension_flag` and
`__handle_subdirs_in_dir_flag` functions with the command name.
Trivial addition to the first example in `README.md` that defines the
`cmd.Execute()` function that is referenced further down in the `main.go`
example.
* Add `CalledAs` method to Command (w/ tests)
The `CalledAs` method returns the name of the command or alias that
invoked the command -- as long as the command was actually invoked.
Otherwise, it returns the empty string.
The opens up possibilies for commands to behave differently based on
which alias invoked the command (in the same vein as Linux programs
which adjust their behavior based on the value of argv[0]).
* Fixed formatting
* Fix attemptd assignment to non-variable in bash 3
flaghash variable is an associative array which is only supported in
bash > 3.
* Use -gt instead of >