Commit graph

621 commits

Author SHA1 Message Date
Albert Nigmatzianov
6d4267ffb7 cmd: Delete redundant symbols from helpers_test.go and licenses.go 2017-04-25 18:25:29 +02:00
Albert Nigmatzianov
78a8032244 cmd: Move some license functions from helpers.go to licenses.go 2017-04-25 18:25:29 +02:00
Albert Nigmatzianov
28fe9aaa16 cmd: Fix GPL 3 License header
See #311
2017-04-25 18:25:29 +02:00
Albert Nigmatzianov
47029cc60a cmd: Delete extra whitespace from GPL 3 License header
Fix #322
2017-04-25 18:25:29 +02:00
Albert Nigmatzianov
f4f10f6873 Simplify stripFlags 2017-04-24 15:20:01 +02:00
Albert Nigmatzianov
63121c8814 Delete Parse from Go projects that uses cobra
http://blog.parse.com/announcements/a-parse-shutdown-reminder/
2017-04-23 22:42:44 +02:00
Albert Nigmatzianov
9890b7b2e9 Simplify stripFlags function 2017-04-23 22:42:38 +02:00
Andrey Kurilin
aea94819d2 Fix typo at docstring for HasHelpSubCommands (#309)
s/avilable/available
2017-04-23 22:29:41 +02:00
Nick Craig-Wood
a4f017e545 Add rclone to list of users (#334) 2017-04-23 22:25:25 +02:00
Francesc Campoy
c4f4d75ecc Use go get so missing dependencies are fetched (#406)
If the developer is missing any dependencies, for instance `github.com/spf13/cobra/cobra`, `go install` will fail:

```bash
../../spf13/viper/util.go:29:2: cannot find package "gopkg.in/yaml.v2" in any of:
        /Users/campoy/src/golang.org/x/go/src/gopkg.in/yaml.v2 (from $GOROOT)
        /Users/campoy/src/gopkg.in/yaml.v2 (from $GOPATH)
```

While `go get github.com/spf13/cobra/cobra` will build the tool successfully.
2017-04-23 18:27:01 +02:00
Albert Nigmatzianov
681a777b18 Delete checkHelpFunc 2017-04-23 09:17:44 +02:00
Albert Nigmatzianov
10f6b9d7e1 Make go path bin clearer in README
Fix #324
2017-04-20 21:54:12 +02:00
Mark D. Blackwell
0a4540b161 Refactor licenses to many files (#323) 2017-04-20 17:34:10 +02:00
Albert Nigmatzianov
f58a8d6bd3 Add TestSortedFlags 2017-04-20 15:38:50 +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
Albert Nigmatzianov
37a4355faa Fix tests 2017-04-20 15:38:50 +02:00
Albert Nigmatzianov
3d89ed4908 Add only missing persistent flags of parents in mergePersistentFlags
As persistent flags of parents can only be added, we don't need to always
check them every time, so make updateParentsPflags return only added flags.

Performance improvement:
benchmark                     old ns/op     new ns/op     delta
BenchmarkInheritedFlags-4     5595          4412          -21.14%
BenchmarkLocalFlags-4         3235          2667          -17.56%

benchmark                     old allocs     new allocs     delta
BenchmarkInheritedFlags-4     39             24             -38.46%
BenchmarkLocalFlags-4         21             15             -28.57%

benchmark                     old bytes     new bytes     delta
BenchmarkInheritedFlags-4     1000          600           -40.00%
BenchmarkLocalFlags-4         544           408           -25.00%
2017-04-20 15:38:50 +02:00
Albert Nigmatzianov
6202b5942b Refactor flags mechanisms
I think It's more obvious now to understand the inheritance of flags.

Fix #403
Fix #404

Performance improvements:
benchmark                     old ns/op     new ns/op     delta
BenchmarkInheritedFlags-4     6536          5595          -14.40%
BenchmarkLocalFlags-4         3193          3235          +1.32%

benchmark                     old allocs     new allocs     delta
BenchmarkInheritedFlags-4     49             39             -20.41%
BenchmarkLocalFlags-4         23             21             -8.70%

benchmark                     old bytes     new bytes     delta
BenchmarkInheritedFlags-4     2040          1000          -50.98%
BenchmarkLocalFlags-4         1008          544           -46.03%
2017-04-20 15:38:50 +02:00
Elliot Morrison-Reed
a3cd8ab85a Use os.Getenv("HOME") instead of "$HOME" for windows compatibility (#337) 2017-04-20 15:35:06 +02:00
Albert Nigmatzianov
b655df6ce8 Get rid of flagErrorBuf (#417)
Fix #27
2017-04-19 09:23:43 -04:00
Albert Nigmatzianov
f95d58bdf3 Fix #401 (#402)
* doc: Add and edit docs

* doc: Add tests
2017-04-19 14:39:58 +02:00
Théotime Lévêque
b6cb395893 Fix typo in docstring (#360) 2017-04-17 19:03:07 +02:00
korya
0a0df1e881 Use valid exit code value in os.Exit call (#405)
Exit code value range is 0-255. I think the examples in the main README document should be valid both syntactically and semantically.
2017-04-17 19:02:17 +02:00
Albert Nigmatzianov
9350054794 Keep only one newline between Aliases and Flags in help (#410)
Fix #409
2017-04-17 18:55:55 +02:00
tomerf
5deb57bbca Fixed completion of dash parameters arguments (#415) 2017-04-08 10:45:37 -04:00
Tamir Duberstein
7aeaa2cce6 Avoid storing pointer to nil (#411)
* 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>
2017-04-02 10:14:34 -04:00
Albert Nigmatzianov
6421115516 doc: Fix govet complaints (#408) 2017-04-01 15:45:39 -05:00
Tamir Duberstein
7be4beda01 remove help command before adding it (#399)
This fixes an issue where each Execute call grows the number of times
`help` appears in the help command by 1.
2017-03-14 12:12:53 -05:00
Sebastiaan van Stijn
16c014f1a1 Add "docker" to readme
Docker (https://github.com/docker/docker) now
also uses Cobra for the CLI. A majority of the
commands have been migrated (still some left),
but adding it already :)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-03-09 10:45:09 -05:00
Albert Nigmatzianov
0960ff7fa9 Rename IsHelpCommand to IsAdditionalHelpTopicCommand (#398)
Fixes #393
2017-03-09 10:37:15 -05:00
Nikola Kovacs
24bb44aac8 Fix SilenceUsage and SilenceErrors in readme (#397)
You have to set them to true to silence the default output, not false.
2017-03-08 14:37:25 -05:00
Albert Nigmatzianov
fcd0c5a1df Some fixes related to help command (#394)
* Add dots in the end of docs

* Make UsageTemplate show help command

Fix #366

* Fix output of help if it's invalid command
2017-02-28 14:17:48 -05:00
Eric Paris
92ea23a837 Fix subcommand locations with NoOptDefValue flags (#391)
If one ran a command like

./root --boolFlag subcmd1 subcmd2

Thing worked fine. The code recognized that --boolFlag followed by a
space meant the next word was not the argument to --boolFlag. But other
flag types with a NoOptDefValue (like a Count flag) would not ignore the
"argument".  On a command like:

./root --countflag subcmd1 subcmd2

The processor, when looking for a subcommand, would first throw out the
`--countflag subcmd1` and then look for subcmd2 under root.

The fix is to ignore the next word after any NoOptDefVal flag, not just
boolean flags.
2017-02-23 08:12:51 -05:00
Bjørn Erik Pedersen
ee4055870c Update the Travis Go versions 2017-02-17 17:45:07 +01:00
Di Xu
b5d8e8f46a cache command name (#390) 2017-02-09 11:54:17 -05:00
Daniel Nephin
99600f6874 Add a tags field for user defined tags on a Command. (#359)
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
2017-02-07 16:20:48 -05:00
French Ben
35136c09d8 Added support for yaml ouptut in docs gen (#380)
Signed-off-by: French Ben <frenchben@docker.com>
2017-01-30 16:45:31 -05:00
Vincent Batts
c29ece4386 Go vet (#345)
* 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>
2017-01-26 14:32:19 -05:00
Oleg Atamanenko
0f056af21f Added godocs to public methods. (#386)
* Added godocs to public methods.

* Fix gofmt formatting.
2017-01-24 11:30:45 -05:00
Apurva Chitnis
dc208f4211 Added useful info for setting up bash autocompletion. (#384) 2017-01-18 13:55:16 -05:00
Raphael 'kena' Poss
1dd5ff2e11 Make SEE ALSO references and generated file names agree with each other. 2016-12-29 00:59:22 -07:00
Philipp Muens
de09d9ce07 Update README with missing import statements (#373) 2016-12-22 10:12:50 -05:00
Qinglan Peng
b62566898a fmt package should be imported (#370)
Signed-off-by: Qinglan Peng <qinglanpeng@zju.edu.cn>
2016-12-14 10:19:52 -05:00
Yuanxiao
9495bc009a echo msg not echo msg msg (#364) 2016-11-16 08:20:53 -05:00
Julien Kassar
6b74a60562 Update doc/man_docs.md (#363) 2016-11-15 09:16:05 -05:00
Ben Gadbois
6e91dded25 Make gofmt -s pass (#355) 2016-10-25 18:28:26 -07:00
Eric Paris
856b96dcb4 Merge pull request #353 from bogem/helpfunc
Fix condition in HelpFunc
2016-10-14 18:20:36 -04:00
bogem
011f19e8ec Fix condition in HelpFunc
I think, it's more obvious, what does this method
2016-10-14 20:34:35 +02:00