Commit graph

828 commits

Author SHA1 Message Date
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
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
Bilal Amarni c6c44e6fdc Update the bash completion example for kubectl (#645) 2018-03-01 10:15:57 -08: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
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
Nick Miyake ccaecb155a Ensure that '--version' flag works properly for root command (#595)
Make it so that, in the case that the root command is not runnable
but has subcommands, specifying a '--version' flag will still
run the "version" behavior.
2017-12-07 08:49:35 +01:00
Jonathan Hall c156af3984 Explain OnInitialize better in the GoDoc (#594) 2017-12-06 19:18:45 +01:00
Allen Sun de2d9c4eca Add alibaba/pouch in README.md (#593)
Signed-off-by: Allen Sun <shlallen1990@gmail.com>
2017-12-04 14:13:25 +01:00
Allen Sun 3a5f27b046 doc: Add a necessary blank line after SEE ALSO (#592)
Signed-off-by: Allen Sun <shlallen1990@gmail.com>
2017-12-04 11:43:02 +01:00
Allen Sun 45a52e208c doc: Remove one additional blank line after Synopsis (#591)
Signed-off-by: Allen Sun <shlallen1990@gmail.com>
2017-12-04 10:21:50 +01:00
Nick Miyake 86783686ca Add documentation for '--version' flag to README (#590) 2017-12-02 18:59:49 +01:00
Nick Miyake b1ec2ce1ad Add support for --version flag (#584) 2017-12-01 22:37:16 +01:00
Nick Miyake 1be1d2841c Make rootCmd private
Update Cobra generator to make rootCmd private rather than
exporting it. Also update examples in README to use the exported
Execute() command rather than referencing unexported rootCmd.

Fixes #556
2017-11-23 08:13:30 +01:00
Nick Miyake fb02817f3c Fix README example to be consistent with others (#585)
Alphabetize and separate builtin imports from external imports
to be gofmt-compliant and consistent with other examples in README.
2017-11-22 16:30:46 -05:00
Nick Miyake 19e54c4a2b Update error message for missing required flags (#580)
Make it so that first letter is not capitalized and rephrase
to remove "have/has".
2017-11-19 10:22:51 +01:00
Daniel Nephin 34ceca591b Disable flags in UseLine (#552)
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
2017-11-19 08:58:54 +01:00
Tyler Butler d6948b782c Fix minor typo (#579) 2017-11-17 00:24:59 -05:00
Albert Nigmatzianov 2da4a54c5c Improve tests in doc/ 2017-11-09 07:56:43 +01:00
Albert Nigmatzianov d6a430541c Edit ResetFlags and ResetCommands descriptions 2017-11-09 07:56:43 +01:00
Albert Nigmatzianov 65c8acb228 Improve tests 2017-11-09 07:56:43 +01:00
Albert Nigmatzianov 099c5aef9e Add dots in comments of args.go 2017-11-09 07:56:43 +01:00
Albert Nigmatzianov 18eefcde17 Add tests for args.go 2017-11-09 07:56:43 +01:00
Pavol Loffay f634327172 Fix typo (#573) 2017-11-08 11:47:54 +01:00
Paweł Słomka b3426bbac1 Remove confusing duplicate Execute from README (#554) 2017-10-29 22:09:45 +01:00
Thomas Cyron 7b2c5ac9fc Create new buffer if not present yet (#549)
Fixes a nil dereference when TraverseChildren is used
with multiple subcommands.
2017-10-12 20:25:33 +02:00
Di Xu 7cd9cc6d44 add test for c.Name() if c.Use gets changed (#548) 2017-10-12 12:50:22 -04:00
Albert Nigmatzianov 40f18800b2 Delete name field from Command (#547)
Discussion: https://github.com/spf13/cobra/pull/422#discussion_r143918343
2017-10-11 10:15:37 -04:00
Kazuki Suda 845c905010 Fix typo 2017-10-11 06:52:18 +02:00
Di Xu 4d6af280c7 enforce required flags (#502) 2017-10-09 23:44:33 -04:00
Clayton Ray 50204810fd Grammar addition (#543)
Just added a comma. Read weird without it
2017-10-09 08:28:07 +02:00
Daniel Nephin 83b1f03962 Add a TraverseChildren option to allow for flags on each command in the hierarchy (#299)
Fix #277 
Fix #467
2017-10-07 23:29:11 +02:00
Shahidh K Muhammed 419e0f8d51 doc: add ReST doc generation (#537) 2017-10-07 19:39:47 +02:00
Albert Nigmatzianov bc69223348 Fix dead link in README for cobra generator
Fix #542
2017-10-06 21:18:12 +02:00
Albert Nigmatzianov e8e7fe0355 Shorten README
Fix #501
2017-10-06 12:20:24 +02:00
Albert Nigmatzianov d5bde60e02 cmd: Fix text of custom license
Fix #540
2017-10-04 22:36:42 +02:00
Diego Becciolini 0dacccfbaa Improve consistency of flags when using SetGlobalNormalizationFunc (#522)
Fix #521
2017-10-02 12:00:25 +02:00