Commit graph

204 commits

Author SHA1 Message Date
Bruce Downs 993cc5372a Adjustments per PR review feedback from @bogem 2019-08-02 01:25:21 +05:00
Bruce Downs 51f06c7dd1 Correct all complaints from golint
* i.e.
* go get golang.org/x/lint/golint
* go list ./... | xargs golint
2019-08-02 01:25:21 +05:00
Bruce Downs 9334a46bd6 Return an error in the case of unrunnable subcommand
* credit to @chriswhelix for initial commit
2019-08-02 01:25:21 +05:00
Juan Leni b635726081 considering stderr in UsageString 2019-06-07 10:48:23 -04:00
Juan Leni cb27ce11fb Deprecate and maintain backwards compatibility 2019-06-07 10:48:23 -04:00
Juan Leni 618bc00f80 Allow for explicit output to err/stderr 2019-06-07 10:48:23 -04:00
Juan Leni 0ea93dd60d Fixed linter issues 2019-06-07 10:48:23 -04:00
Juan Leni 4a716d101b Extending redirection to stdout, stderr, stdin 2019-06-07 10:48:23 -04:00
umarcor 5755ecf102 [TrivialPatches] Typos in README.md, fix and update CI, update projects list... (#840)
* 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
2019-03-20 17:21:26 -04:00
Rajat Jindal 4dab30cb33 Add support for ignoring parse errors (#662) 2018-03-31 08:36:20 -04:00
Di Xu c439c4fa09 Terminate the stripping of flags when -- is found (#649) 2018-03-19 11:20:04 +05: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
Shamus Taylor 3a7eb146ba fix grammatical error in command.go (#626) 2018-02-01 22:04:56 -08: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
Nick Miyake b1ec2ce1ad Add support for --version flag (#584) 2017-12-01 22:37:16 +01: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
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
Pavol Loffay f634327172 Fix typo (#573) 2017-11-08 11:47:54 +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
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
Di Xu 4d6af280c7 enforce required flags (#502) 2017-10-09 23:44:33 -04: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
Diego Becciolini 0dacccfbaa Improve consistency of flags when using SetGlobalNormalizationFunc (#522)
Fix #521
2017-10-02 12:00:25 +02:00
Albert Nigmatzianov 1723331773 Update documentation 2017-08-23 12:32:09 +05:00
Daniel Nephin f20b4e9c32 Refactor TakesArgs to use an interface for arg validation.
Fix some typos in README and comments.
Move arg validation to after flag validation so that the help flag is run first.
Pass the same args to ValidateArgs as the Run methods receive.
Update README.

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
2017-07-23 09:57:27 +02:00
Eric Paris d89c499964 Allow commands to explicitly state if they do, or do not take arbitrary arguments
Check that arguments are in ValidArgs

If a command defined cmd.ValidArgs check that the argument is actually
in ValidArgs and fail if it is not.
2017-07-23 09:57:27 +02:00
Albert Nigmatzianov d994347eda Delete tab in the long description of help 2017-07-16 12:48:02 +02:00
Albert Nigmatzianov 8c6fa02d22 Fix InitDefaultHelpCmd when custom help command is set 2017-06-29 12:52:34 +02:00
Albert Nigmatzianov 99b5d838ca Show messages if deprecated flags are used
Fix #463
2017-06-19 23:05:29 +02:00
Albert Nigmatzianov e606913c4e Fix typos 2017-05-28 12:56:30 +02:00
Albert Nigmatzianov 52ae6a1d02 Make initHelpCmd public (#436)
Useful for solving #424
2017-05-20 19:23:33 +02:00
Albert Nigmatzianov 51b7cf57e1 Fix tests so they give correct args (#445)
* Fix tests so they give correct args

Shell already deletes all quotes and unite args under quotes, so we
don't need to test it.

* Simplify stripFlags

* Fix 'unused' and 'gosimple' complaints
2017-05-14 08:51:04 -04:00
Albert Nigmatzianov 7d22e77cce Fix incorrect merge of pflag.CommandLine to cmd.Flags()
Fix #443
2017-05-12 20:22:26 +02:00
Albert Nigmatzianov eceb483eb5 Divide fields of Command for readability 2017-05-09 11:33:56 +02:00
Albert Nigmatzianov 90d2fd84ad Group fields of Command 2017-05-09 11:25:41 +02:00
Albert Nigmatzianov 4db577d34d Fix docs for Command 2017-05-09 11:15:05 +02:00
Albert Nigmatzianov 4d2c4afa04 Improve template mechanisms
* Delete Eq, Gt, appendIfNotPresent and trim functions

* Add "[flags]" in UseLine

* Simplify other functions

* Simplify templates

Minor performance improvement.
Benchmark for command with 4 flags and one child command:
benchmark                   old ns/op     new ns/op     delta
BenchmarkCmdUsageFunc-4     335860        319290        -4.93%

benchmark                   old allocs     new allocs     delta
BenchmarkCmdUsageFunc-4     562            543            -3.38%

benchmark                   old bytes     new bytes     delta
BenchmarkCmdUsageFunc-4     21623         21037         -2.71%
2017-05-08 14:22:04 +02:00
Albert Nigmatzianov d83a1d7ccd Add comment for InitDefaultHelpFlag 2017-05-07 10:52:40 +02:00
Albert Nigmatzianov fe69f2e3a3 Make initHelpFlag public
Used for solving #424
2017-05-07 00:45:39 +02:00
Albert Nigmatzianov 4061f41c9a Use pflag.ShorthandLookup 2017-05-05 08:08:38 +02:00
Albert Nigmatzianov 3d7bff8a32 Revert "Get rid of flagErrorBuf (#417)"
This reverts commit b655df6ce8.

Reason for revert: duplicate errors from flag. More in #426

Fix #426
2017-04-27 15:10:57 +02:00
Albert Nigmatzianov 867d414548 Initialize help flag in initHelpCmd
Fix #302
2017-04-26 21:24:14 +02:00
Albert Nigmatzianov f4f10f6873 Simplify stripFlags 2017-04-24 15:20:01 +02:00
Albert Nigmatzianov 9890b7b2e9 Simplify stripFlags function 2017-04-23 22:42:38 +02:00
Albert Nigmatzianov 681a777b18 Delete checkHelpFunc 2017-04-23 09:17:44 +02:00
Albert Nigmatzianov e135867f96 Make parentsPflags more flexible
updateParentsPflags returns nothing, so you can use it independent of
mergePersistentFlags. A little performance impact.
2017-04-20 15:38:50 +02:00
Albert Nigmatzianov 3e61377cd5 Use AddFlagSet instead of self-written function 2017-04-20 15:38:50 +02:00
Albert Nigmatzianov 458d79748e Add merging of CommandLine flags to Root command 2017-04-20 15:38:50 +02:00