Skip to content
Myr

[TrivialPatches] Typos in README.md, fix and update CI, update projects list... (#840)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* 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

authored by umarcor · committed by Eric Paris · parent ba1052d · Browse files · 7 files+118 added−39 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+118 added−39 removed

  • other:+118 added−39 removed

7 files+118 added−39 removed

modified:.circleci/config.yml+3 added-3 removed
modified:cobra/cmd/golden_test.go+6 added-1 removed
15 unmodified lines
16 addCmd.SetOutput(new(bytes.Buffer))17 initCmd.SetOutput(new(bytes.Buffer))18}1920// ensureLF converts any \r\n to \n21func ensureLF(content []byte) []byte {22 return bytes.Replace(content, []byte("\r\n"), []byte("\n"), -1)23}2425// compareFiles compares the content of files with pathA and pathB.26// If contents are equal, it returns nil.27// If not, it returns which files are not equal28// and diff (if system has diff command) between these files.
5 unmodified lines
34 contentB, err := ioutil.ReadFile(pathB)35 if err != nil {36 return err37 }33 if !bytes.Equal(contentA, contentB) {38 if !bytes.Equal(ensureLF(contentA), ensureLF(contentB)) {39 output := new(bytes.Buffer)40 output.WriteString(fmt.Sprintf("%q and %q are not equal!\n\n", pathA, pathB))4142 diffPath, err := exec.LookPath("diff")
40 unmodified lines
modified:.travis.yml+18 added-9 removed
modified:command.go+2 added-4 removed
815 unmodified lines
816 // initialize help as the last point possible to allow for user817 // overriding818 c.InitDefaultHelpCmd()819820 var args []string820 args := c.args821822 // Workaround FAIL with "go test -v" or "cobra.test -test.v", see #155823 if c.args == nil && filepath.Base(os.Args[0]) != "cobra.test" {824 args = os.Args[1:]825 } else {826 args = c.args825 }826827 var flags []string828 if c.TraverseChildren {
503 unmodified lines
1332 c.PersistentFlags().VisitAll(addToLocal)1333 return c.lflags1334}13351338// InheritedFlags returns all flags which were inherited from parents commands.1336// InheritedFlags returns all flags which were inherited from parent commands.1337func (c *Command) InheritedFlags() *flag.FlagSet {1338 c.mergePersistentFlags()13391340 if c.iflags == nil {
175 unmodified lines
added:go.mod+13 added
1module github.com/spf13/cobra23go 1.1245require (6 github.com/BurntSushi/toml v0.3.1 // indirect7 github.com/cpuguy83/go-md2man v1.0.108 github.com/inconshreveable/mousetrap v1.0.09 github.com/mitchellh/go-homedir v1.1.010 github.com/spf13/pflag v1.0.311 github.com/spf13/viper v1.3.212 gopkg.in/yaml.v2 v2.2.213)
added:go.sum+51 added
1github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=2github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=3github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=4github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=5github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=6github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=7github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=8github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=9github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=10github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=11github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=12github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=13github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=14github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=15github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=16github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=17github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=18github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=19github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=20github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=21github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=22github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=23github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=24github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=25github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=26github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=27github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=28github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=29github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=30github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=31github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=32github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=33github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=34github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=35github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=36github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=37github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=38github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=39github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=40github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=41github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=42github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=43golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=44golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A=45golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=46golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=47golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=48gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=49gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=50gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=51gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
modified:README.md+25 added-22 removed
1![cobra logo](https://cloud.githubusercontent.com/assets/173412/10886352/ad566232-814f-11e5-9cd0-aa101788c117.png)23Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files.45Many of the most widely used Go projects are built using Cobra including:5Many of the most widely used Go projects are built using Cobra, such as:6[Kubernetes](http://kubernetes.io/),7[Hugo](http://gohugo.io),8[rkt](https://github.com/coreos/rkt),9[etcd](https://github.com/coreos/etcd),10[Moby (former Docker)](https://github.com/moby/moby),11[Docker (distribution)](https://github.com/docker/distribution),12[OpenShift](https://www.openshift.com/),13[Delve](https://github.com/derekparker/delve),14[GopherJS](http://www.gopherjs.org/),15[CockroachDB](http://www.cockroachlabs.com/),16[Bleve](http://www.blevesearch.com/),17[ProjectAtomic (enterprise)](http://www.projectatomic.io/),18[Giant Swarm's gsctl](https://github.com/giantswarm/gsctl),19[Nanobox](https://github.com/nanobox-io/nanobox)/[Nanopack](https://github.com/nanopack),20[rclone](http://rclone.org/),21[nehm](https://github.com/bogem/nehm),22[Pouch](https://github.com/alibaba/pouch),23[Istio](https://istio.io),24[Prototool](https://github.com/uber/prototool),25[mattermost-server](https://github.com/mattermost/mattermost-server),26etc.277* [Kubernetes](http://kubernetes.io/)8* [Hugo](http://gohugo.io)9* [rkt](https://github.com/coreos/rkt)10* [etcd](https://github.com/coreos/etcd)11* [Moby (former Docker)](https://github.com/moby/moby)12* [Docker (distribution)](https://github.com/docker/distribution)13* [OpenShift](https://www.openshift.com/)14* [Delve](https://github.com/derekparker/delve)15* [GopherJS](http://www.gopherjs.org/)16* [CockroachDB](http://www.cockroachlabs.com/)17* [Bleve](http://www.blevesearch.com/)18* [ProjectAtomic (enterprise)](http://www.projectatomic.io/)19* [Giant Swarm's gsctl](https://github.com/giantswarm/gsctl)20* [Nanobox](https://github.com/nanobox-io/nanobox)/[Nanopack](https://github.com/nanopack)21* [rclone](http://rclone.org/)22* [nehm](https://github.com/bogem/nehm)23* [Pouch](https://github.com/alibaba/pouch)2428[![Build Status](https://travis-ci.org/spf13/cobra.svg "Travis CI status")](https://travis-ci.org/spf13/cobra)29[![CircleCI status](https://circleci.com/gh/spf13/cobra.png?circle-token=:circle-token "CircleCI status")](https://circleci.com/gh/spf13/cobra)30[![GoDoc](https://godoc.org/github.com/spf13/cobra?status.svg)](https://godoc.org/github.com/spf13/cobra)31
359 unmodified lines
391- `OnlyValidArgs` - the command will report an error if there are any positional args that are not in the `ValidArgs` field of `Command`.392- `MinimumNArgs(int)` - the command will report an error if there are not at least N positional args.393- `MaximumNArgs(int)` - the command will report an error if there are more than N positional args.394- `ExactArgs(int)` - the command will report an error if there are not exactly N positional args.392- `ExactValidArgs(int)` = the command will report and error if there are not exactly N positional args OR if there are any positional args that are not in the `ValidArgs` field of `Command`395- `ExactValidArgs(int)` - the command will report an error if there are not exactly N positional args OR if there are any positional args that are not in the `ValidArgs` field of `Command`396- `RangeArgs(min, max)` - the command will report an error if the number of args is not between the minimum and maximum number of expected args.397398An example of setting the custom validator:399
1 unmodified line
401var cmd = &cobra.Command{402 Short: "hello",403 Args: func(cmd *cobra.Command, args []string) error {404 if len(args) < 1 {402 return errors.New("requires at least one arg")405 return errors.New("requires a color argument")406 }407 if myapp.IsValidColor(args[0]) {408 return nil409 }
51 unmodified lines
461 },462 }463464 var cmdTimes = &cobra.Command{462 Use: "times [# times] [string to echo]",465 Use: "times [string to echo]",466 Short: "Echo anything to the screen more times",467 Long: `echo things multiple times back to the user by providing468a count and a string.`,469 Args: cobra.MinimumNArgs(1),
265 unmodified lines