summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/cobra/cobra
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/cobra/cobra')
-rw-r--r--vendor/github.com/spf13/cobra/cobra/README.md94
-rw-r--r--vendor/github.com/spf13/cobra/cobra/cmd/helpers.go23
-rw-r--r--vendor/github.com/spf13/cobra/cobra/cmd/licenses.go2
3 files changed, 117 insertions, 2 deletions
diff --git a/vendor/github.com/spf13/cobra/cobra/README.md b/vendor/github.com/spf13/cobra/cobra/README.md
new file mode 100644
index 000000000..6054f95c5
--- /dev/null
+++ b/vendor/github.com/spf13/cobra/cobra/README.md
@@ -0,0 +1,94 @@
+# Cobra Generator
+
+Cobra provides its own program that will create your application and add any
+commands you want. It's the easiest way to incorporate Cobra into your application.
+
+In order to use the cobra command, compile it using the following command:
+
+ go get github.com/spf13/cobra/cobra
+
+This will create the cobra executable under your `$GOPATH/bin` directory.
+
+### cobra init
+
+The `cobra init [app]` command will create your initial application code
+for you. It is a very powerful application that will populate your program with
+the right structure so you can immediately enjoy all the benefits of Cobra. It
+will also automatically apply the license you specify to your application.
+
+Cobra init is pretty smart. You can provide it a full path, or simply a path
+similar to what is expected in the import.
+
+```
+cobra init github.com/spf13/newApp
+```
+
+### cobra add
+
+Once an application is initialized, Cobra can create additional commands for you.
+Let's say you created an app and you wanted the following commands for it:
+
+* app serve
+* app config
+* app config create
+
+In your project directory (where your main.go file is) you would run the following:
+
+```
+cobra add serve
+cobra add config
+cobra add create -p 'configCmd'
+```
+
+*Note: Use camelCase (not snake_case/snake-case) for command names.
+Otherwise, you will encounter errors.
+For example, `cobra add add-user` is incorrect, but `cobra add addUser` is valid.*
+
+Once you have run these three commands you would have an app structure similar to
+the following:
+
+```
+ ▾ app/
+ ▾ cmd/
+ serve.go
+ config.go
+ create.go
+ main.go
+```
+
+At this point you can run `go run main.go` and it would run your app. `go run
+main.go serve`, `go run main.go config`, `go run main.go config create` along
+with `go run main.go help serve`, etc. would all work.
+
+Obviously you haven't added your own code to these yet. The commands are ready
+for you to give them their tasks. Have fun!
+
+### Configuring the cobra generator
+
+The Cobra generator will be easier to use if you provide a simple configuration
+file which will help you eliminate providing a bunch of repeated information in
+flags over and over.
+
+An example ~/.cobra.yaml file:
+
+```yaml
+author: Steve Francia <spf@spf13.com>
+license: MIT
+```
+
+You can specify no license by setting `license` to `none` or you can specify
+a custom license:
+
+```yaml
+license:
+ header: This file is part of {{ .appName }}.
+ text: |
+ {{ .copyright }}
+
+ This is my license. There are many like it, but this one is mine.
+ My license is my best friend. It is my life. I must master it as I must
+ master my life.
+```
+
+You can also use built-in licenses. For example, **GPLv2**, **GPLv3**, **LGPL**,
+**AGPL**, **MIT**, **2-Clause BSD** or **3-Clause BSD**.
diff --git a/vendor/github.com/spf13/cobra/cobra/cmd/helpers.go b/vendor/github.com/spf13/cobra/cobra/cmd/helpers.go
index c5e261ce3..e5b37ec72 100644
--- a/vendor/github.com/spf13/cobra/cobra/cmd/helpers.go
+++ b/vendor/github.com/spf13/cobra/cobra/cmd/helpers.go
@@ -18,6 +18,7 @@ import (
"fmt"
"io"
"os"
+ "os/exec"
"path/filepath"
"strings"
"text/template"
@@ -31,7 +32,27 @@ func init() {
envGoPath := os.Getenv("GOPATH")
goPaths := filepath.SplitList(envGoPath)
if len(goPaths) == 0 {
- er("$GOPATH is not set")
+ // Adapted from https://github.com/Masterminds/glide/pull/798/files.
+ // As of Go 1.8 the GOPATH is no longer required to be set. Instead there
+ // is a default value. If there is no GOPATH check for the default value.
+ // Note, checking the GOPATH first to avoid invoking the go toolchain if
+ // possible.
+
+ goExecutable := os.Getenv("COBRA_GO_EXECUTABLE")
+ if len(goExecutable) <= 0 {
+ goExecutable = "go"
+ }
+
+ out, err := exec.Command(goExecutable, "env", "GOPATH").Output()
+ if err != nil {
+ er(err)
+ }
+
+ toolchainGoPath := strings.TrimSpace(string(out))
+ goPaths = filepath.SplitList(toolchainGoPath)
+ if len(goPaths) == 0 {
+ er("$GOPATH is not set")
+ }
}
srcPaths = make([]string, 0, len(goPaths))
for _, goPath := range goPaths {
diff --git a/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go b/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go
index cf2a6b7af..a070134dd 100644
--- a/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go
+++ b/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go
@@ -63,7 +63,7 @@ func getLicense() License {
// If user wants to have custom license, use that.
if viper.IsSet("license.header") || viper.IsSet("license.text") {
return License{Header: viper.GetString("license.header"),
- Text: "license.text"}
+ Text: viper.GetString("license.text")}
}
// If user wants to have built-in license, use that.