Commit graph

659 commits

Author SHA1 Message Date
Haim Ashkenazi
13b42c0440 Merge remote-tracking branch 'spf13/master' into zsh-completion 2018-06-02 06:39:42 +03:00
Jason Hendry
1e58aa3361 Include a basic example #465 (#631) 2018-05-31 14:03:38 -04:00
Zef Hemel
ef82de70bb Fixed code sample for bash completion (#687) 2018-04-27 09:45:50 -04:00
James DeFelice
0ab5b6bcfc doc: hide hidden parent flags (#686)
* fixes #685
2018-04-24 12:15:12 -04:00
Rajat Jindal
7ee208b09f support completions for command aliases (#669)
* support completions for command aliases

* try newer version of shellcheck

* initialize aliashash only when BASH_VERSION > 3
2018-04-23 08:47:20 -04:00
Haim Ashkenazi
a223d1bd4b Merge remote-tracking branch 'spf13/master' into zsh-completion 2018-04-19 07:42:50 +03:00
Rajat Jindal
615425954c remove dot after the abs path (#672) 2018-04-12 08:08:29 -04:00
Allen Sun
cd30c2a7e9 typo: fix incorrect (#668)
Signed-off-by: Allen Sun <shlallen1990@gmail.com>
2018-04-08 12:17:36 -04:00
Rajat Jindal
4dab30cb33 Add support for ignoring parse errors (#662) 2018-03-31 08:36:20 -04:00
Haim Ashkenazi
1fc860f55f typo in zsh-completions.md 2018-03-23 13:57:53 +03:00
Haim Ashkenazi
484eff9644 zsh-completions: implemented argument completion. 2018-03-23 13:09:56 +03:00
Haim Ashkenazi
4c6a1bc7fc Merge remote-tracking branch 'spf13/master' into zsh-completion 2018-03-22 20:00:57 +02:00
Haim Ashkenazi
00618a4f66 zsh-completion: tidy up function and variable names
There are many files in the package, renamed all zsh-completion
related names to convey that.
2018-03-22 19:58:25 +02:00
Michael
a1f051bc3e Update the Travis and CircleCI Go versions (#651) 2018-03-21 09:39:34 -05:00
Di Xu
c439c4fa09 Terminate the stripping of flags when -- is found (#649) 2018-03-19 11:20:04 +05:00
Haim Ashkenazi
d57d0497c3 zsh-completion: added escapinng of single quotes in flag description. 2018-03-17 20:55:27 +02:00
Haim Ashkenazi
70fa250801 zsh-completion: test to verify that we're always running on root cmd. 2018-03-05 01:09:55 +02:00
Haim Ashkenazi
f57cec37ef zsh-completion: --version and --help still doesn't work correctly
When invoking from subcommand. Modified the test to prove.
2018-03-05 00:46:00 +02:00
Haim Ashkenazi
70f3e356eb zsh-completion: completion should always parse the root command!
It was running on the command it was invoked from which caused some
additional helpers (--help, --version) not to be generated.
2018-03-04 23:56:31 +02:00
Haim Ashkenazi
ee1d5ce55b zsh-completion: remove bad test
I thought there was a bug in the boolSlice definition but it seems
It was my mistake in identifying what's going on. Also removed the
provisioning to skip tests (doesn't seem to be needed anymore).
2018-03-03 20:35:17 +02:00
Haim Ashkenazi
d5412f0772 zsh-completion: remove temporary file
Yet another temporary file that found itself in the repo :(
2018-03-03 14:50:58 +02:00
Haim Ashkenazi
7dc860db89 Merge remote-tracking branch 'spf13/master' into zsh-completion 2018-03-03 14:50:22 +02:00
Haim Ashkenazi
6ada43c6e8 zsh-completion: added support for filename globbing. 2018-03-02 14:00:08 +02:00
Bilal Amarni
c6c44e6fdc Update the bash completion example for kubectl (#645) 2018-03-01 10:15:57 -08:00
Haim Ashkenazi
11cf991a56 zsh-completions: fixed zsh completion markdown file name. 2018-03-01 08:53:25 +02:00
Haim Ashkenazi
43f884fa23 zsh-completion: added zsh-completion documentation. 2018-03-01 08:50:20 +02:00
Haim Ashkenazi
d925cc6916 zsh-completion: removed forgotten function. 2018-03-01 08:02:33 +02:00
Haim Ashkenazi
9df4b2fced zsh-completion: two fixes for identifying flag usage:
Fixed after input from @eparis:
- Decide on option parameter by checking NoOptDefVal
- Slices also could be specified multiple times.
2018-02-28 21:52:35 +02:00
Haim Ashkenazi
be021cb03a zsh-completion: removed the _dep_ files.
They were committed by mistake.
2018-02-28 21:09:10 +02:00
Haim Ashkenazi
c99a50b65c Merge upstream into zsh-completion 2018-02-28 17:14:40 +02:00
Haim Ashkenazi
f7c1ed9054 zsh-completions: revised flags completion rendering + new features:
- 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 :)
2018-02-28 17:04:17 +02:00
Haim Ashkenazi
91a14a05fe zsh-completion template refactoring:
- removed redundant function
- improved other functions :)
- better names for other functions
2018-02-28 12:49:53 +02:00
John McCabe
6644d46b81 Prefix bash functions with root command name (#643)
* 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>
2018-02-27 21:38:38 -08:00
Haim Ashkenazi
991feef2f5 zsh-completion: added support for subcommand description.
Also make the template more elegant on the way...
2018-02-26 22:31:06 +02:00
Haim Ashkenazi
c978c0bd7d Merge remote-tracking branch 'spf13/master' into zsh-completion 2018-02-25 14:17:08 +02:00
Haim Ashkenazi
7091b88f98 zsh-completion ignores hidden commands and flags :) 2018-02-25 14:12:58 +02:00
Haim Ashkenazi
892ebc0721 zsh-completion fixed reference to cmd name
cmd.Use is not the command name :). Found it once I figured out
that I need to execute the command in order to fully test the
generated completion.
2018-02-25 08:20:34 +02:00
Haim Ashkenazi
3100f0b575 First try at better zsh completions:
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?
2018-02-24 18:53:13 +02:00
Rajat Jindal
a1e4933ab7 Bash completion aliases (#638)
* alias support with bash completions

* add cmdname to rootcmdname

* remove print statement

* add documentation for bash alias
2018-02-21 09:51:53 -08:00
Eric Paris
1a618fb24b
Do not add a space after a single flag completion (#625) 2018-02-21 07:50:56 -08:00
Ricardo N Feliciano
be77323fc0 Try out CircleCI. (#630) 2018-02-11 17:22:30 +01:00
John McCabe
fd32f09af1 Fix generated bash completion for Bash 3 (OSX) (#520)
* 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.
2018-02-08 13:34:46 -08:00
Phillip Johnsen
93959269ad Add Execute func example in README.md (#629)
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.
2018-02-05 14:42:58 -08:00
Jake Dodd
c2bbfaa12d Add usage example for required flags (#627)
* Add usage example for required flags

* Explain new behavior in MarkFlagRequired godocs
2018-02-05 11:53:53 -08:00
Tim Peoples
eb58983359 Add CalledAs method to cobra.Command (w/ tests) (#567)
* 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
2018-02-04 08:58:53 -08:00
Kazuki Suda
9979838ec4 Fix attemptd assignment to non-variable in bash 3 (#628)
* 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 >
2018-02-04 08:42:17 -08:00
Shamus Taylor
3a7eb146ba fix grammatical error in command.go (#626) 2018-02-01 22:04:56 -08:00
Ryan Guest
f91529fc60 Fix a couple typos (#621) 2018-01-24 08:31:43 +01:00
Albert Nigmatzianov
0c34d16c31
cmd: Fix #612 (#614)
If user has a project in symlink, just use its destination folder and
work there.
2018-01-15 17:09:33 +01:00
Patrick Uiterwijk
b95ab734e2 Remove trailing whitespace in rootcmd (#606)
Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
2017-12-31 15:15:56 +05:00