Add command to generate man pages
The climan package has a command that can be registered with any urfav cli app to generate man pages. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
		
							
								
								
									
										302
									
								
								vendor/github.com/urfave/cli/README.md
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										302
									
								
								vendor/github.com/urfave/cli/README.md
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -3,15 +3,11 @@ cli | ||||
|  | ||||
| [](https://travis-ci.org/urfave/cli) | ||||
| [](https://ci.appveyor.com/project/urfave/cli) | ||||
|  | ||||
| [](https://godoc.org/github.com/urfave/cli) | ||||
| [](https://codebeat.co/projects/github-com-urfave-cli) | ||||
| [](https://goreportcard.com/report/urfave/cli) | ||||
| [](http://gocover.io/github.com/urfave/cli) / | ||||
| [](http://gocover.io/github.com/urfave/cli/altsrc) | ||||
|  | ||||
| **Notice:** This is the library formerly known as | ||||
| `github.com/codegangsta/cli` -- Github will automatically redirect requests | ||||
| to this repository, but we recommend updating your references for clarity. | ||||
| [](https://codecov.io/gh/urfave/cli) | ||||
|  | ||||
| cli is a simple, fast, and fun package for building command line apps in Go. The | ||||
| goal is to enable developers to write fast and distributable command line | ||||
| @@ -23,7 +19,7 @@ applications in an expressive way. | ||||
| - [Installation](#installation) | ||||
|   * [Supported platforms](#supported-platforms) | ||||
|   * [Using the `v2` branch](#using-the-v2-branch) | ||||
|   * [Pinning to the `v1` releases](#pinning-to-the-v1-releases) | ||||
|   * [Using `v1` releases](#using-v1-releases) | ||||
| - [Getting Started](#getting-started) | ||||
| - [Examples](#examples) | ||||
|   * [Arguments](#arguments) | ||||
| @@ -32,11 +28,13 @@ applications in an expressive way. | ||||
|     + [Alternate Names](#alternate-names) | ||||
|     + [Ordering](#ordering) | ||||
|     + [Values from the Environment](#values-from-the-environment) | ||||
|     + [Values from files](#values-from-files) | ||||
|     + [Values from alternate input sources (YAML, TOML, and others)](#values-from-alternate-input-sources-yaml-toml-and-others) | ||||
|     + [Precedence](#precedence) | ||||
|   * [Subcommands](#subcommands) | ||||
|   * [Subcommands categories](#subcommands-categories) | ||||
|   * [Exit code](#exit-code) | ||||
|   * [Combining short options](#combining-short-options) | ||||
|   * [Bash Completion](#bash-completion) | ||||
|     + [Enabling](#enabling) | ||||
|     + [Distribution](#distribution) | ||||
| @@ -62,7 +60,7 @@ organized, and expressive! | ||||
|  | ||||
| ## Installation | ||||
|  | ||||
| Make sure you have a working Go environment.  Go version 1.2+ is supported.  [See | ||||
| Make sure you have a working Go environment.  Go version 1.10+ is supported.  [See | ||||
| the install instructions for Go](http://golang.org/doc/install.html). | ||||
|  | ||||
| To install cli, simply run: | ||||
| @@ -106,25 +104,20 @@ import ( | ||||
| ... | ||||
| ``` | ||||
|  | ||||
| ### Pinning to the `v1` releases | ||||
|  | ||||
| Similarly to the section above describing use of the `v2` branch, if one wants | ||||
| to avoid any unexpected compatibility pains once `v2` becomes `master`, then | ||||
| pinning to `v1` is an acceptable option, e.g.: | ||||
| ### Using `v1` releases | ||||
|  | ||||
| ``` | ||||
| $ go get gopkg.in/urfave/cli.v1 | ||||
| $ go get github.com/urfave/cli | ||||
| ``` | ||||
|  | ||||
| ``` go | ||||
| ```go | ||||
| ... | ||||
| import ( | ||||
|   "gopkg.in/urfave/cli.v1" // imports as package "cli" | ||||
|   "github.com/urfave/cli" | ||||
| ) | ||||
| ... | ||||
| ``` | ||||
|  | ||||
| This will pull the latest tagged `v1` release (e.g. `v1.18.1` at the time of writing). | ||||
|  | ||||
| ## Getting Started | ||||
|  | ||||
| @@ -139,13 +132,17 @@ discovery. So a cli app can be as little as one line of code in `main()`. | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
|   cli.NewApp().Run(os.Args) | ||||
|   err := cli.NewApp().Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -160,6 +157,7 @@ package main | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -174,7 +172,10 @@ func main() { | ||||
|     return nil | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -198,6 +199,7 @@ package main | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -212,7 +214,10 @@ func main() { | ||||
|     return nil | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -261,6 +266,7 @@ package main | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -274,7 +280,10 @@ func main() { | ||||
|     return nil | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -290,6 +299,7 @@ package main | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -319,7 +329,10 @@ func main() { | ||||
|     return nil | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -333,6 +346,7 @@ scanned. | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|   "fmt" | ||||
|  | ||||
| @@ -366,7 +380,10 @@ func main() { | ||||
|     return nil | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -387,6 +404,7 @@ For example this: | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -402,7 +420,10 @@ func main() { | ||||
|     }, | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -428,6 +449,7 @@ list for the `Name`. e.g. | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -444,7 +466,10 @@ func main() { | ||||
|     }, | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -468,6 +493,7 @@ For example this: | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|   "sort" | ||||
|  | ||||
| @@ -511,7 +537,10 @@ func main() { | ||||
|   sort.Sort(cli.FlagsByName(app.Flags)) | ||||
|   sort.Sort(cli.CommandsByName(app.Commands)) | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -534,6 +563,7 @@ You can also have the default value set from the environment via `EnvVar`.  e.g. | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -551,7 +581,10 @@ func main() { | ||||
|     }, | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -566,6 +599,7 @@ environment variable that resolves is used as the default. | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -583,10 +617,52 @@ func main() { | ||||
|     }, | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| #### Values from files | ||||
|  | ||||
| You can also have the default value set from file via `FilePath`.  e.g. | ||||
|  | ||||
| <!-- { | ||||
|   "args": ["--help"], | ||||
|   "output": "password for the mysql database" | ||||
| } --> | ||||
| ``` go | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
|   app := cli.NewApp() | ||||
|  | ||||
|   app.Flags = []cli.Flag { | ||||
|     cli.StringFlag{ | ||||
|       Name: "password, p", | ||||
|       Usage: "password for the mysql database", | ||||
|       FilePath: "/etc/mysql/password", | ||||
|     }, | ||||
|   } | ||||
|  | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| Note that default values set from file (e.g. `FilePath`) take precedence over | ||||
| default values set from the environment (e.g. `EnvVar`). | ||||
|  | ||||
| #### Values from alternate input sources (YAML, TOML, and others) | ||||
|  | ||||
| There is a separate package altsrc that adds support for getting flag values | ||||
| @@ -594,6 +670,7 @@ from other file input sources. | ||||
|  | ||||
| Currently supported input source formats: | ||||
| * YAML | ||||
| * JSON | ||||
| * TOML | ||||
|  | ||||
| In order to get values for a flag from an alternate input source the following | ||||
| @@ -616,9 +693,9 @@ the yaml input source for any flags that are defined on that command.  As a note | ||||
| the "load" flag used would also have to be defined on the command flags in order | ||||
| for this code snipped to work. | ||||
|  | ||||
| Currently only the aboved specified formats are supported but developers can | ||||
| add support for other input sources by implementing the | ||||
| altsrc.InputSourceContext for their given sources. | ||||
| Currently only YAML, JSON, and TOML files are supported but developers can add support | ||||
| for other input sources by implementing the altsrc.InputSourceContext for their | ||||
| given sources. | ||||
|  | ||||
| Here is a more complete sample of a command using YAML support: | ||||
|  | ||||
| @@ -631,6 +708,7 @@ package notmain | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -653,7 +731,10 @@ func main() { | ||||
|   app.Before = altsrc.InitInputSourceWithContext(flags, altsrc.NewYamlSourceFromFlagFunc("load")) | ||||
|   app.Flags = flags | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -679,6 +760,7 @@ package main | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -731,7 +813,10 @@ func main() { | ||||
|     }, | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -747,6 +832,7 @@ E.g. | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -769,7 +855,10 @@ func main() { | ||||
|     }, | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -777,7 +866,7 @@ Will include: | ||||
|  | ||||
| ``` | ||||
| COMMANDS: | ||||
|     noop | ||||
|   noop | ||||
|  | ||||
|   Template actions: | ||||
|     add | ||||
| @@ -790,11 +879,14 @@ Calling `App.Run` will not automatically call `os.Exit`, which means that by | ||||
| default the exit code will "fall through" to being `0`.  An explicit exit code | ||||
| may be set by returning a non-nil error that fulfills `cli.ExitCoder`, *or* a | ||||
| `cli.MultiError` that includes an error that fulfills `cli.ExitCoder`, e.g.: | ||||
|  | ||||
| <!-- { | ||||
|   "error": "Ginger croutons are not in the soup" | ||||
| } --> | ||||
| ``` go | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -803,22 +895,95 @@ import ( | ||||
| func main() { | ||||
|   app := cli.NewApp() | ||||
|   app.Flags = []cli.Flag{ | ||||
|     cli.BoolTFlag{ | ||||
|     cli.BoolFlag{ | ||||
|       Name:  "ginger-crouton", | ||||
|       Usage: "is it in the soup?", | ||||
|       Usage: "Add ginger croutons to the soup", | ||||
|     }, | ||||
|   } | ||||
|   app.Action = func(ctx *cli.Context) error { | ||||
|     if !ctx.Bool("ginger-crouton") { | ||||
|       return cli.NewExitError("it is not in the soup", 86) | ||||
|       return cli.NewExitError("Ginger croutons are not in the soup", 86) | ||||
|     } | ||||
|     return nil | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| ### Combining short options | ||||
|  | ||||
| Traditional use of options using their shortnames look like this: | ||||
|  | ||||
| ``` | ||||
| $ cmd -s -o -m "Some message" | ||||
| ``` | ||||
|  | ||||
| Suppose you want users to be able to combine options with their shortnames. This | ||||
| can be done using the `UseShortOptionHandling` bool in your app configuration, | ||||
| or for individual commands by attaching it to the command configuration. For | ||||
| example: | ||||
|  | ||||
| <!-- { | ||||
|   "args": ["short", "-som", "Some message"], | ||||
|   "output": "serve: true\noption: true\nmessage: Some message\n" | ||||
| } --> | ||||
| ``` go | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
|   app := cli.NewApp() | ||||
|   app.UseShortOptionHandling = true | ||||
|   app.Commands = []cli.Command{ | ||||
|     { | ||||
|       Name:  "short", | ||||
|       Usage: "complete a task on the list", | ||||
|       Flags: []cli.Flag{ | ||||
|         cli.BoolFlag{Name: "serve, s"}, | ||||
|         cli.BoolFlag{Name: "option, o"}, | ||||
|         cli.StringFlag{Name: "message, m"}, | ||||
|       }, | ||||
|       Action: func(c *cli.Context) error { | ||||
|         fmt.Println("serve:", c.Bool("serve")) | ||||
|         fmt.Println("option:", c.Bool("option")) | ||||
|         fmt.Println("message:", c.String("message")) | ||||
|         return nil | ||||
|       }, | ||||
|     }, | ||||
|   } | ||||
|  | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| If your program has any number of bool flags such as `serve` and `option`, and | ||||
| optionally one non-bool flag `message`, with the short options of `-s`, `-o`, | ||||
| and `-m` respectively, setting `UseShortOptionHandling` will also support the | ||||
| following syntax: | ||||
|  | ||||
| ``` | ||||
| $ cmd -som "Some message" | ||||
| ``` | ||||
|  | ||||
| If you enable `UseShortOptionHandling`, then you must not use any flags that | ||||
| have a single leading `-` or this will result in failures. For example, | ||||
| `-option` can no longer be used. Flags with two leading dashes (such as | ||||
| `--options`) are still valid. | ||||
|  | ||||
| ### Bash Completion | ||||
|  | ||||
| You can enable completion commands by setting the `EnableBashCompletion` | ||||
| @@ -835,6 +1000,7 @@ package main | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -866,7 +1032,10 @@ func main() { | ||||
|     }, | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -906,6 +1075,7 @@ The default bash completion flag (`--generate-bash-completion`) is defined as | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -924,7 +1094,10 @@ func main() { | ||||
|       Name: "wat", | ||||
|     }, | ||||
|   } | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -950,6 +1123,7 @@ package main | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "io" | ||||
|   "os" | ||||
|  | ||||
| @@ -993,7 +1167,10 @@ VERSION: | ||||
|     fmt.Println("Ha HA.  I pwnd the help!!1") | ||||
|   } | ||||
|  | ||||
|   cli.NewApp().Run(os.Args) | ||||
|   err := cli.NewApp().Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -1008,6 +1185,7 @@ setting `cli.HelpFlag`, e.g.: | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -1020,7 +1198,10 @@ func main() { | ||||
|     EnvVar: "SHOW_HALP,HALPPLZ", | ||||
|   } | ||||
|  | ||||
|   cli.NewApp().Run(os.Args) | ||||
|   err := cli.NewApp().Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -1043,6 +1224,7 @@ setting `cli.VersionFlag`, e.g.: | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -1057,7 +1239,10 @@ func main() { | ||||
|   app := cli.NewApp() | ||||
|   app.Name = "partay" | ||||
|   app.Version = "19.99.0" | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -1072,6 +1257,7 @@ package main | ||||
|  | ||||
| import ( | ||||
|   "fmt" | ||||
|   "log" | ||||
|   "os" | ||||
|  | ||||
|   "github.com/urfave/cli" | ||||
| @@ -1089,7 +1275,10 @@ func main() { | ||||
|   app := cli.NewApp() | ||||
|   app.Name = "partay" | ||||
|   app.Version = "19.99.0" | ||||
|   app.Run(os.Args) | ||||
|   err := app.Run(os.Args) | ||||
|   if err != nil { | ||||
|     log.Fatal(err) | ||||
|   } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -1246,6 +1435,7 @@ func main() { | ||||
|     cli.Uint64Flag{Name: "bigage"}, | ||||
|   } | ||||
|   app.EnableBashCompletion = true | ||||
|   app.UseShortOptionHandling = true | ||||
|   app.HideHelp = false | ||||
|   app.HideVersion = false | ||||
|   app.BashComplete = func(c *cli.Context) { | ||||
| @@ -1351,7 +1541,7 @@ func main() { | ||||
|     ec := cli.NewExitError("ohwell", 86) | ||||
|     fmt.Fprintf(c.App.Writer, "%d", ec.ExitCode()) | ||||
|     fmt.Printf("made it!\n") | ||||
|     return ec | ||||
|     return nil | ||||
|   } | ||||
|  | ||||
|   if os.Getenv("HEXY") != "" { | ||||
| @@ -1365,7 +1555,9 @@ func main() { | ||||
|     "whatever-values": 19.99, | ||||
|   } | ||||
|  | ||||
|   app.Run(os.Args) | ||||
|  | ||||
|   // ignore error so we don't exit non-zero and break gfmrun README example tests | ||||
|   _ = app.Run(os.Args) | ||||
| } | ||||
|  | ||||
| func wopAction(c *cli.Context) error { | ||||
| @@ -1376,16 +1568,4 @@ func wopAction(c *cli.Context) error { | ||||
|  | ||||
| ## Contribution Guidelines | ||||
|  | ||||
| Feel free to put up a pull request to fix a bug or maybe add a feature. I will | ||||
| give it a code review and make sure that it does not break backwards | ||||
| compatibility. If I or any other collaborators agree that it is in line with | ||||
| the vision of the project, we will work with you to get the code into | ||||
| a mergeable state and merge it into the master branch. | ||||
|  | ||||
| If you have contributed something significant to the project, we will most | ||||
| likely add you as a collaborator. As a collaborator you are given the ability | ||||
| to merge others pull requests. It is very important that new code does not | ||||
| break existing code, so be careful about what code you do choose to merge. | ||||
|  | ||||
| If you feel like you have contributed to the project but have not yet been | ||||
| added as a collaborator, we probably forgot to add you, please open an issue. | ||||
| See [./CONTRIBUTING.md](./CONTRIBUTING.md) | ||||
|   | ||||
							
								
								
									
										85
									
								
								vendor/github.com/urfave/cli/app.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										85
									
								
								vendor/github.com/urfave/cli/app.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,9 +1,9 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"io/ioutil" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"sort" | ||||
| @@ -11,9 +11,10 @@ import ( | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	changeLogURL                    = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" | ||||
| 	appActionDeprecationURL         = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) | ||||
| 	runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL) | ||||
| 	changeLogURL            = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" | ||||
| 	appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) | ||||
| 	// unused variable. commented for now. will remove in future if agreed upon by everyone | ||||
| 	//runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL) | ||||
|  | ||||
| 	contactSysadmin = "This is an error in the application.  Please contact the distributor of this application if this is not you." | ||||
|  | ||||
| @@ -94,6 +95,10 @@ type App struct { | ||||
| 	// cli.go uses text/template to render templates. You can | ||||
| 	// render custom help text by setting this variable. | ||||
| 	CustomAppHelpTemplate string | ||||
| 	// Boolean to enable short-option handling so user can combine several | ||||
| 	// single-character bool arguements into one | ||||
| 	// i.e. foobar -o -v -> foobar -ov | ||||
| 	UseShortOptionHandling bool | ||||
|  | ||||
| 	didSetup bool | ||||
| } | ||||
| @@ -138,7 +143,7 @@ func (a *App) Setup() { | ||||
| 		a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email}) | ||||
| 	} | ||||
|  | ||||
| 	newCmds := []Command{} | ||||
| 	var newCmds []Command | ||||
| 	for _, c := range a.Commands { | ||||
| 		if c.HelpName == "" { | ||||
| 			c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) | ||||
| @@ -173,6 +178,14 @@ func (a *App) Setup() { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (a *App) newFlagSet() (*flag.FlagSet, error) { | ||||
| 	return flagSet(a.Name, a.Flags) | ||||
| } | ||||
|  | ||||
| func (a *App) useShortOptionHandling() bool { | ||||
| 	return a.UseShortOptionHandling | ||||
| } | ||||
|  | ||||
| // Run is the entry point to the cli app. Parses the arguments slice and routes | ||||
| // to the proper flag/args combination | ||||
| func (a *App) Run(arguments []string) (err error) { | ||||
| @@ -186,19 +199,17 @@ func (a *App) Run(arguments []string) (err error) { | ||||
| 	// always appends the completion flag at the end of the command | ||||
| 	shellComplete, arguments := checkShellCompleteFlag(a, arguments) | ||||
|  | ||||
| 	// parse flags | ||||
| 	set, err := flagSet(a.Name, a.Flags) | ||||
| 	_, err = a.newFlagSet() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	set.SetOutput(ioutil.Discard) | ||||
| 	err = set.Parse(arguments[1:]) | ||||
| 	set, err := parseIter(a, arguments[1:]) | ||||
| 	nerr := normalizeFlags(a.Flags, set) | ||||
| 	context := NewContext(a, set, nil) | ||||
| 	if nerr != nil { | ||||
| 		fmt.Fprintln(a.Writer, nerr) | ||||
| 		ShowAppHelp(context) | ||||
| 		_, _ = fmt.Fprintln(a.Writer, nerr) | ||||
| 		_ = ShowAppHelp(context) | ||||
| 		return nerr | ||||
| 	} | ||||
| 	context.shellComplete = shellComplete | ||||
| @@ -213,13 +224,13 @@ func (a *App) Run(arguments []string) (err error) { | ||||
| 			a.handleExitCoder(context, err) | ||||
| 			return err | ||||
| 		} | ||||
| 		fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) | ||||
| 		ShowAppHelp(context) | ||||
| 		_, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) | ||||
| 		_ = ShowAppHelp(context) | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if !a.HideHelp && checkHelp(context) { | ||||
| 		ShowAppHelp(context) | ||||
| 		_ = ShowAppHelp(context) | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| @@ -228,6 +239,12 @@ func (a *App) Run(arguments []string) (err error) { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	cerr := checkRequiredFlags(a.Flags, context) | ||||
| 	if cerr != nil { | ||||
| 		_ = ShowAppHelp(context) | ||||
| 		return cerr | ||||
| 	} | ||||
|  | ||||
| 	if a.After != nil { | ||||
| 		defer func() { | ||||
| 			if afterErr := a.After(context); afterErr != nil { | ||||
| @@ -243,8 +260,8 @@ func (a *App) Run(arguments []string) (err error) { | ||||
| 	if a.Before != nil { | ||||
| 		beforeErr := a.Before(context) | ||||
| 		if beforeErr != nil { | ||||
| 			fmt.Fprintf(a.Writer, "%v\n\n", beforeErr) | ||||
| 			ShowAppHelp(context) | ||||
| 			_, _ = fmt.Fprintf(a.Writer, "%v\n\n", beforeErr) | ||||
| 			_ = ShowAppHelp(context) | ||||
| 			a.handleExitCoder(context, beforeErr) | ||||
| 			err = beforeErr | ||||
| 			return err | ||||
| @@ -278,7 +295,7 @@ func (a *App) Run(arguments []string) (err error) { | ||||
| // code in the cli.ExitCoder | ||||
| func (a *App) RunAndExitOnError() { | ||||
| 	if err := a.Run(os.Args); err != nil { | ||||
| 		fmt.Fprintln(a.errWriter(), err) | ||||
| 		_, _ = fmt.Fprintln(a.errWriter(), err) | ||||
| 		OsExiter(1) | ||||
| 	} | ||||
| } | ||||
| @@ -305,24 +322,22 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { | ||||
| 	} | ||||
| 	a.Commands = newCmds | ||||
|  | ||||
| 	// parse flags | ||||
| 	set, err := flagSet(a.Name, a.Flags) | ||||
| 	_, err = a.newFlagSet() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	set.SetOutput(ioutil.Discard) | ||||
| 	err = set.Parse(ctx.Args().Tail()) | ||||
| 	set, err := parseIter(a, ctx.Args().Tail()) | ||||
| 	nerr := normalizeFlags(a.Flags, set) | ||||
| 	context := NewContext(a, set, ctx) | ||||
|  | ||||
| 	if nerr != nil { | ||||
| 		fmt.Fprintln(a.Writer, nerr) | ||||
| 		fmt.Fprintln(a.Writer) | ||||
| 		_, _ = fmt.Fprintln(a.Writer, nerr) | ||||
| 		_, _ = fmt.Fprintln(a.Writer) | ||||
| 		if len(a.Commands) > 0 { | ||||
| 			ShowSubcommandHelp(context) | ||||
| 			_ = ShowSubcommandHelp(context) | ||||
| 		} else { | ||||
| 			ShowCommandHelp(ctx, context.Args().First()) | ||||
| 			_ = ShowCommandHelp(ctx, context.Args().First()) | ||||
| 		} | ||||
| 		return nerr | ||||
| 	} | ||||
| @@ -337,8 +352,8 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { | ||||
| 			a.handleExitCoder(context, err) | ||||
| 			return err | ||||
| 		} | ||||
| 		fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) | ||||
| 		ShowSubcommandHelp(context) | ||||
| 		_, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) | ||||
| 		_ = ShowSubcommandHelp(context) | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| @@ -352,6 +367,12 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	cerr := checkRequiredFlags(a.Flags, context) | ||||
| 	if cerr != nil { | ||||
| 		_ = ShowSubcommandHelp(context) | ||||
| 		return cerr | ||||
| 	} | ||||
|  | ||||
| 	if a.After != nil { | ||||
| 		defer func() { | ||||
| 			afterErr := a.After(context) | ||||
| @@ -428,7 +449,7 @@ func (a *App) VisibleCategories() []*CommandCategory { | ||||
|  | ||||
| // VisibleCommands returns a slice of the Commands with Hidden=false | ||||
| func (a *App) VisibleCommands() []Command { | ||||
| 	ret := []Command{} | ||||
| 	var ret []Command | ||||
| 	for _, command := range a.Commands { | ||||
| 		if !command.Hidden { | ||||
| 			ret = append(ret, command) | ||||
| @@ -453,7 +474,6 @@ func (a *App) hasFlag(flag Flag) bool { | ||||
| } | ||||
|  | ||||
| func (a *App) errWriter() io.Writer { | ||||
|  | ||||
| 	// When the app ErrWriter is nil use the package level one. | ||||
| 	if a.ErrWriter == nil { | ||||
| 		return ErrWriter | ||||
| @@ -496,11 +516,12 @@ func (a Author) String() string { | ||||
| // it's an ActionFunc or a func with the legacy signature for Action, the func | ||||
| // is run! | ||||
| func HandleAction(action interface{}, context *Context) (err error) { | ||||
| 	if a, ok := action.(ActionFunc); ok { | ||||
| 	switch a := action.(type) { | ||||
| 	case ActionFunc: | ||||
| 		return a(context) | ||||
| 	} else if a, ok := action.(func(*Context) error); ok { | ||||
| 	case func(*Context) error: | ||||
| 		return a(context) | ||||
| 	} else if a, ok := action.(func(*Context)); ok { // deprecated function signature | ||||
| 	case func(*Context): // deprecated function signature | ||||
| 		a(context) | ||||
| 		return nil | ||||
| 	} | ||||
|   | ||||
							
								
								
									
										2
									
								
								vendor/github.com/urfave/cli/category.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/urfave/cli/category.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -10,7 +10,7 @@ type CommandCategory struct { | ||||
| } | ||||
|  | ||||
| func (c CommandCategories) Less(i, j int) bool { | ||||
| 	return c[i].Name < c[j].Name | ||||
| 	return lexicographicLess(c[i].Name, c[j].Name) | ||||
| } | ||||
|  | ||||
| func (c CommandCategories) Len() int { | ||||
|   | ||||
							
								
								
									
										2
									
								
								vendor/github.com/urfave/cli/cli.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/urfave/cli/cli.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -19,4 +19,4 @@ | ||||
| //   } | ||||
| package cli | ||||
|  | ||||
| //go:generate python ./generate-flag-types cli -i flag-types.json -o flag_generated.go | ||||
| //go:generate go run flag-gen/main.go flag-gen/assets_vfsdata.go | ||||
|   | ||||
							
								
								
									
										141
									
								
								vendor/github.com/urfave/cli/command.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										141
									
								
								vendor/github.com/urfave/cli/command.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,8 +1,8 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
| ) | ||||
| @@ -55,6 +55,10 @@ type Command struct { | ||||
| 	HideHelp bool | ||||
| 	// Boolean to hide this command from help or completion | ||||
| 	Hidden bool | ||||
| 	// Boolean to enable short-option handling so user can combine several | ||||
| 	// single-character bool arguments into one | ||||
| 	// i.e. foobar -o -v -> foobar -ov | ||||
| 	UseShortOptionHandling bool | ||||
|  | ||||
| 	// Full name of command for help, defaults to full command name, including parent commands. | ||||
| 	HelpName        string | ||||
| @@ -73,7 +77,7 @@ func (c CommandsByName) Len() int { | ||||
| } | ||||
|  | ||||
| func (c CommandsByName) Less(i, j int) bool { | ||||
| 	return c[i].Name < c[j].Name | ||||
| 	return lexicographicLess(c[i].Name, c[j].Name) | ||||
| } | ||||
|  | ||||
| func (c CommandsByName) Swap(i, j int) { | ||||
| @@ -106,57 +110,11 @@ func (c Command) Run(ctx *Context) (err error) { | ||||
| 		) | ||||
| 	} | ||||
|  | ||||
| 	set, err := flagSet(c.Name, c.Flags) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	set.SetOutput(ioutil.Discard) | ||||
|  | ||||
| 	if c.SkipFlagParsing { | ||||
| 		err = set.Parse(append([]string{"--"}, ctx.Args().Tail()...)) | ||||
| 	} else if !c.SkipArgReorder { | ||||
| 		firstFlagIndex := -1 | ||||
| 		terminatorIndex := -1 | ||||
| 		for index, arg := range ctx.Args() { | ||||
| 			if arg == "--" { | ||||
| 				terminatorIndex = index | ||||
| 				break | ||||
| 			} else if arg == "-" { | ||||
| 				// Do nothing. A dash alone is not really a flag. | ||||
| 				continue | ||||
| 			} else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 { | ||||
| 				firstFlagIndex = index | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if firstFlagIndex > -1 { | ||||
| 			args := ctx.Args() | ||||
| 			regularArgs := make([]string, len(args[1:firstFlagIndex])) | ||||
| 			copy(regularArgs, args[1:firstFlagIndex]) | ||||
|  | ||||
| 			var flagArgs []string | ||||
| 			if terminatorIndex > -1 { | ||||
| 				flagArgs = args[firstFlagIndex:terminatorIndex] | ||||
| 				regularArgs = append(regularArgs, args[terminatorIndex:]...) | ||||
| 			} else { | ||||
| 				flagArgs = args[firstFlagIndex:] | ||||
| 			} | ||||
|  | ||||
| 			err = set.Parse(append(flagArgs, regularArgs...)) | ||||
| 		} else { | ||||
| 			err = set.Parse(ctx.Args().Tail()) | ||||
| 		} | ||||
| 	} else { | ||||
| 		err = set.Parse(ctx.Args().Tail()) | ||||
| 	if ctx.App.UseShortOptionHandling { | ||||
| 		c.UseShortOptionHandling = true | ||||
| 	} | ||||
|  | ||||
| 	nerr := normalizeFlags(c.Flags, set) | ||||
| 	if nerr != nil { | ||||
| 		fmt.Fprintln(ctx.App.Writer, nerr) | ||||
| 		fmt.Fprintln(ctx.App.Writer) | ||||
| 		ShowCommandHelp(ctx, c.Name) | ||||
| 		return nerr | ||||
| 	} | ||||
| 	set, err := c.parseFlags(ctx.Args().Tail()) | ||||
|  | ||||
| 	context := NewContext(ctx.App, set, ctx) | ||||
| 	context.Command = c | ||||
| @@ -170,9 +128,9 @@ func (c Command) Run(ctx *Context) (err error) { | ||||
| 			context.App.handleExitCoder(context, err) | ||||
| 			return err | ||||
| 		} | ||||
| 		fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error()) | ||||
| 		fmt.Fprintln(context.App.Writer) | ||||
| 		ShowCommandHelp(context, c.Name) | ||||
| 		_, _ = fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error()) | ||||
| 		_, _ = fmt.Fprintln(context.App.Writer) | ||||
| 		_ = ShowCommandHelp(context, c.Name) | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| @@ -180,6 +138,12 @@ func (c Command) Run(ctx *Context) (err error) { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	cerr := checkRequiredFlags(c.Flags, context) | ||||
| 	if cerr != nil { | ||||
| 		_ = ShowCommandHelp(context, c.Name) | ||||
| 		return cerr | ||||
| 	} | ||||
|  | ||||
| 	if c.After != nil { | ||||
| 		defer func() { | ||||
| 			afterErr := c.After(context) | ||||
| @@ -197,7 +161,7 @@ func (c Command) Run(ctx *Context) (err error) { | ||||
| 	if c.Before != nil { | ||||
| 		err = c.Before(context) | ||||
| 		if err != nil { | ||||
| 			ShowCommandHelp(context, c.Name) | ||||
| 			_ = ShowCommandHelp(context, c.Name) | ||||
| 			context.App.handleExitCoder(context, err) | ||||
| 			return err | ||||
| 		} | ||||
| @@ -215,6 +179,71 @@ func (c Command) Run(ctx *Context) (err error) { | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (c *Command) parseFlags(args Args) (*flag.FlagSet, error) { | ||||
| 	if c.SkipFlagParsing { | ||||
| 		set, err := c.newFlagSet() | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
|  | ||||
| 		return set, set.Parse(append([]string{"--"}, args...)) | ||||
| 	} | ||||
|  | ||||
| 	if !c.SkipArgReorder { | ||||
| 		args = reorderArgs(args) | ||||
| 	} | ||||
|  | ||||
| 	set, err := parseIter(c, args) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	err = normalizeFlags(c.Flags, set) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return set, nil | ||||
| } | ||||
|  | ||||
| func (c *Command) newFlagSet() (*flag.FlagSet, error) { | ||||
| 	return flagSet(c.Name, c.Flags) | ||||
| } | ||||
|  | ||||
| func (c *Command) useShortOptionHandling() bool { | ||||
| 	return c.UseShortOptionHandling | ||||
| } | ||||
|  | ||||
| // reorderArgs moves all flags before arguments as this is what flag expects | ||||
| func reorderArgs(args []string) []string { | ||||
| 	var nonflags, flags []string | ||||
|  | ||||
| 	readFlagValue := false | ||||
| 	for i, arg := range args { | ||||
| 		if arg == "--" { | ||||
| 			nonflags = append(nonflags, args[i:]...) | ||||
| 			break | ||||
| 		} | ||||
|  | ||||
| 		if readFlagValue && !strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") { | ||||
| 			readFlagValue = false | ||||
| 			flags = append(flags, arg) | ||||
| 			continue | ||||
| 		} | ||||
| 		readFlagValue = false | ||||
|  | ||||
| 		if arg != "-" && strings.HasPrefix(arg, "-") { | ||||
| 			flags = append(flags, arg) | ||||
|  | ||||
| 			readFlagValue = !strings.Contains(arg, "=") | ||||
| 		} else { | ||||
| 			nonflags = append(nonflags, arg) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return append(flags, nonflags...) | ||||
| } | ||||
|  | ||||
| // Names returns the names including short names and aliases. | ||||
| func (c Command) Names() []string { | ||||
| 	names := []string{c.Name} | ||||
| @@ -239,6 +268,7 @@ func (c Command) HasName(name string) bool { | ||||
| func (c Command) startApp(ctx *Context) error { | ||||
| 	app := NewApp() | ||||
| 	app.Metadata = ctx.App.Metadata | ||||
| 	app.ExitErrHandler = ctx.App.ExitErrHandler | ||||
| 	// set the name and usage | ||||
| 	app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name) | ||||
| 	if c.HelpName == "" { | ||||
| @@ -267,6 +297,7 @@ func (c Command) startApp(ctx *Context) error { | ||||
| 	app.Email = ctx.App.Email | ||||
| 	app.Writer = ctx.App.Writer | ||||
| 	app.ErrWriter = ctx.App.ErrWriter | ||||
| 	app.UseShortOptionHandling = ctx.App.UseShortOptionHandling | ||||
|  | ||||
| 	app.categories = CommandCategories{} | ||||
| 	for _, command := range c.Subcommands { | ||||
|   | ||||
							
								
								
									
										80
									
								
								vendor/github.com/urfave/cli/context.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										80
									
								
								vendor/github.com/urfave/cli/context.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -3,6 +3,8 @@ package cli | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| 	"syscall" | ||||
| @@ -93,18 +95,26 @@ func (c *Context) IsSet(name string) bool { | ||||
| 					val = val.Elem() | ||||
| 				} | ||||
|  | ||||
| 				envVarValue := val.FieldByName("EnvVar") | ||||
| 				if !envVarValue.IsValid() { | ||||
| 					return | ||||
| 				filePathValue := val.FieldByName("FilePath") | ||||
| 				if filePathValue.IsValid() { | ||||
| 					eachName(filePathValue.String(), func(filePath string) { | ||||
| 						if _, err := os.Stat(filePath); err == nil { | ||||
| 							c.setFlags[name] = true | ||||
| 							return | ||||
| 						} | ||||
| 					}) | ||||
| 				} | ||||
|  | ||||
| 				eachName(envVarValue.String(), func(envVar string) { | ||||
| 					envVar = strings.TrimSpace(envVar) | ||||
| 					if _, ok := syscall.Getenv(envVar); ok { | ||||
| 						c.setFlags[name] = true | ||||
| 						return | ||||
| 					} | ||||
| 				}) | ||||
| 				envVarValue := val.FieldByName("EnvVar") | ||||
| 				if envVarValue.IsValid() { | ||||
| 					eachName(envVarValue.String(), func(envVar string) { | ||||
| 						envVar = strings.TrimSpace(envVar) | ||||
| 						if _, ok := syscall.Getenv(envVar); ok { | ||||
| 							c.setFlags[name] = true | ||||
| 							return | ||||
| 						} | ||||
| 					}) | ||||
| 				} | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
| @@ -129,8 +139,8 @@ func (c *Context) GlobalIsSet(name string) bool { | ||||
|  | ||||
| // FlagNames returns a slice of flag names used in this context. | ||||
| func (c *Context) FlagNames() (names []string) { | ||||
| 	for _, flag := range c.Command.Flags { | ||||
| 		name := strings.Split(flag.GetName(), ",")[0] | ||||
| 	for _, f := range c.Command.Flags { | ||||
| 		name := strings.Split(f.GetName(), ",")[0] | ||||
| 		if name == "help" { | ||||
| 			continue | ||||
| 		} | ||||
| @@ -141,8 +151,8 @@ func (c *Context) FlagNames() (names []string) { | ||||
|  | ||||
| // GlobalFlagNames returns a slice of global flag names used by the app. | ||||
| func (c *Context) GlobalFlagNames() (names []string) { | ||||
| 	for _, flag := range c.App.Flags { | ||||
| 		name := strings.Split(flag.GetName(), ",")[0] | ||||
| 	for _, f := range c.App.Flags { | ||||
| 		name := strings.Split(f.GetName(), ",")[0] | ||||
| 		if name == "help" || name == "version" { | ||||
| 			continue | ||||
| 		} | ||||
| @@ -240,7 +250,7 @@ func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) { | ||||
| 	switch ff.Value.(type) { | ||||
| 	case *StringSlice: | ||||
| 	default: | ||||
| 		set.Set(name, ff.Value.String()) | ||||
| 		_ = set.Set(name, ff.Value.String()) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -276,3 +286,43 @@ func normalizeFlags(flags []Flag, set *flag.FlagSet) error { | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| type requiredFlagsErr interface { | ||||
| 	error | ||||
| 	getMissingFlags() []string | ||||
| } | ||||
|  | ||||
| type errRequiredFlags struct { | ||||
| 	missingFlags []string | ||||
| } | ||||
|  | ||||
| func (e *errRequiredFlags) Error() string { | ||||
| 	numberOfMissingFlags := len(e.missingFlags) | ||||
| 	if numberOfMissingFlags == 1 { | ||||
| 		return fmt.Sprintf("Required flag %q not set", e.missingFlags[0]) | ||||
| 	} | ||||
| 	joinedMissingFlags := strings.Join(e.missingFlags, ", ") | ||||
| 	return fmt.Sprintf("Required flags %q not set", joinedMissingFlags) | ||||
| } | ||||
|  | ||||
| func (e *errRequiredFlags) getMissingFlags() []string { | ||||
| 	return e.missingFlags | ||||
| } | ||||
|  | ||||
| func checkRequiredFlags(flags []Flag, context *Context) requiredFlagsErr { | ||||
| 	var missingFlags []string | ||||
| 	for _, f := range flags { | ||||
| 		if rf, ok := f.(RequiredFlag); ok && rf.IsRequired() { | ||||
| 			key := strings.Split(f.GetName(), ",")[0] | ||||
| 			if !context.IsSet(key) { | ||||
| 				missingFlags = append(missingFlags, key) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if len(missingFlags) != 0 { | ||||
| 		return &errRequiredFlags{missingFlags: missingFlags} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
							
								
								
									
										148
									
								
								vendor/github.com/urfave/cli/docs.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								vendor/github.com/urfave/cli/docs.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,148 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
| 	"text/template" | ||||
|  | ||||
| 	"github.com/cpuguy83/go-md2man/v2/md2man" | ||||
| ) | ||||
|  | ||||
| // ToMarkdown creates a markdown string for the `*App` | ||||
| // The function errors if either parsing or writing of the string fails. | ||||
| func (a *App) ToMarkdown() (string, error) { | ||||
| 	var w bytes.Buffer | ||||
| 	if err := a.writeDocTemplate(&w); err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| 	return w.String(), nil | ||||
| } | ||||
|  | ||||
| // ToMan creates a man page string for the `*App` | ||||
| // The function errors if either parsing or writing of the string fails. | ||||
| func (a *App) ToMan() (string, error) { | ||||
| 	var w bytes.Buffer | ||||
| 	if err := a.writeDocTemplate(&w); err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| 	man := md2man.Render(w.Bytes()) | ||||
| 	return string(man), nil | ||||
| } | ||||
|  | ||||
| type cliTemplate struct { | ||||
| 	App          *App | ||||
| 	Commands     []string | ||||
| 	GlobalArgs   []string | ||||
| 	SynopsisArgs []string | ||||
| } | ||||
|  | ||||
| func (a *App) writeDocTemplate(w io.Writer) error { | ||||
| 	const name = "cli" | ||||
| 	t, err := template.New(name).Parse(MarkdownDocTemplate) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return t.ExecuteTemplate(w, name, &cliTemplate{ | ||||
| 		App:          a, | ||||
| 		Commands:     prepareCommands(a.Commands, 0), | ||||
| 		GlobalArgs:   prepareArgsWithValues(a.Flags), | ||||
| 		SynopsisArgs: prepareArgsSynopsis(a.Flags), | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func prepareCommands(commands []Command, level int) []string { | ||||
| 	coms := []string{} | ||||
| 	for i := range commands { | ||||
| 		command := &commands[i] | ||||
| 		if command.Hidden { | ||||
| 			continue | ||||
| 		} | ||||
| 		usage := "" | ||||
| 		if command.Usage != "" { | ||||
| 			usage = command.Usage | ||||
| 		} | ||||
|  | ||||
| 		prepared := fmt.Sprintf("%s %s\n\n%s\n", | ||||
| 			strings.Repeat("#", level+2), | ||||
| 			strings.Join(command.Names(), ", "), | ||||
| 			usage, | ||||
| 		) | ||||
|  | ||||
| 		flags := prepareArgsWithValues(command.Flags) | ||||
| 		if len(flags) > 0 { | ||||
| 			prepared += fmt.Sprintf("\n%s", strings.Join(flags, "\n")) | ||||
| 		} | ||||
|  | ||||
| 		coms = append(coms, prepared) | ||||
|  | ||||
| 		// recursevly iterate subcommands | ||||
| 		if len(command.Subcommands) > 0 { | ||||
| 			coms = append( | ||||
| 				coms, | ||||
| 				prepareCommands(command.Subcommands, level+1)..., | ||||
| 			) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return coms | ||||
| } | ||||
|  | ||||
| func prepareArgsWithValues(flags []Flag) []string { | ||||
| 	return prepareFlags(flags, ", ", "**", "**", `""`, true) | ||||
| } | ||||
|  | ||||
| func prepareArgsSynopsis(flags []Flag) []string { | ||||
| 	return prepareFlags(flags, "|", "[", "]", "[value]", false) | ||||
| } | ||||
|  | ||||
| func prepareFlags( | ||||
| 	flags []Flag, | ||||
| 	sep, opener, closer, value string, | ||||
| 	addDetails bool, | ||||
| ) []string { | ||||
| 	args := []string{} | ||||
| 	for _, f := range flags { | ||||
| 		flag, ok := f.(DocGenerationFlag) | ||||
| 		if !ok { | ||||
| 			continue | ||||
| 		} | ||||
| 		modifiedArg := opener | ||||
| 		for _, s := range strings.Split(flag.GetName(), ",") { | ||||
| 			trimmed := strings.TrimSpace(s) | ||||
| 			if len(modifiedArg) > len(opener) { | ||||
| 				modifiedArg += sep | ||||
| 			} | ||||
| 			if len(trimmed) > 1 { | ||||
| 				modifiedArg += fmt.Sprintf("--%s", trimmed) | ||||
| 			} else { | ||||
| 				modifiedArg += fmt.Sprintf("-%s", trimmed) | ||||
| 			} | ||||
| 		} | ||||
| 		modifiedArg += closer | ||||
| 		if flag.TakesValue() { | ||||
| 			modifiedArg += fmt.Sprintf("=%s", value) | ||||
| 		} | ||||
|  | ||||
| 		if addDetails { | ||||
| 			modifiedArg += flagDetails(flag) | ||||
| 		} | ||||
|  | ||||
| 		args = append(args, modifiedArg+"\n") | ||||
|  | ||||
| 	} | ||||
| 	sort.Strings(args) | ||||
| 	return args | ||||
| } | ||||
|  | ||||
| // flagDetails returns a string containing the flags metadata | ||||
| func flagDetails(flag DocGenerationFlag) string { | ||||
| 	description := flag.GetUsage() | ||||
| 	value := flag.GetValue() | ||||
| 	if value != "" { | ||||
| 		description += " (default: " + value + ")" | ||||
| 	} | ||||
| 	return ": " + description | ||||
| } | ||||
							
								
								
									
										194
									
								
								vendor/github.com/urfave/cli/fish.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										194
									
								
								vendor/github.com/urfave/cli/fish.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,194 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"strings" | ||||
| 	"text/template" | ||||
| ) | ||||
|  | ||||
| // ToFishCompletion creates a fish completion string for the `*App` | ||||
| // The function errors if either parsing or writing of the string fails. | ||||
| func (a *App) ToFishCompletion() (string, error) { | ||||
| 	var w bytes.Buffer | ||||
| 	if err := a.writeFishCompletionTemplate(&w); err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| 	return w.String(), nil | ||||
| } | ||||
|  | ||||
| type fishCompletionTemplate struct { | ||||
| 	App         *App | ||||
| 	Completions []string | ||||
| 	AllCommands []string | ||||
| } | ||||
|  | ||||
| func (a *App) writeFishCompletionTemplate(w io.Writer) error { | ||||
| 	const name = "cli" | ||||
| 	t, err := template.New(name).Parse(FishCompletionTemplate) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	allCommands := []string{} | ||||
|  | ||||
| 	// Add global flags | ||||
| 	completions := a.prepareFishFlags(a.VisibleFlags(), allCommands) | ||||
|  | ||||
| 	// Add help flag | ||||
| 	if !a.HideHelp { | ||||
| 		completions = append( | ||||
| 			completions, | ||||
| 			a.prepareFishFlags([]Flag{HelpFlag}, allCommands)..., | ||||
| 		) | ||||
| 	} | ||||
|  | ||||
| 	// Add version flag | ||||
| 	if !a.HideVersion { | ||||
| 		completions = append( | ||||
| 			completions, | ||||
| 			a.prepareFishFlags([]Flag{VersionFlag}, allCommands)..., | ||||
| 		) | ||||
| 	} | ||||
|  | ||||
| 	// Add commands and their flags | ||||
| 	completions = append( | ||||
| 		completions, | ||||
| 		a.prepareFishCommands(a.VisibleCommands(), &allCommands, []string{})..., | ||||
| 	) | ||||
|  | ||||
| 	return t.ExecuteTemplate(w, name, &fishCompletionTemplate{ | ||||
| 		App:         a, | ||||
| 		Completions: completions, | ||||
| 		AllCommands: allCommands, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (a *App) prepareFishCommands(commands []Command, allCommands *[]string, previousCommands []string) []string { | ||||
| 	completions := []string{} | ||||
| 	for i := range commands { | ||||
| 		command := &commands[i] | ||||
|  | ||||
| 		if command.Hidden { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		var completion strings.Builder | ||||
| 		completion.WriteString(fmt.Sprintf( | ||||
| 			"complete -r -c %s -n '%s' -a '%s'", | ||||
| 			a.Name, | ||||
| 			a.fishSubcommandHelper(previousCommands), | ||||
| 			strings.Join(command.Names(), " "), | ||||
| 		)) | ||||
|  | ||||
| 		if command.Usage != "" { | ||||
| 			completion.WriteString(fmt.Sprintf(" -d '%s'", | ||||
| 				escapeSingleQuotes(command.Usage))) | ||||
| 		} | ||||
|  | ||||
| 		if !command.HideHelp { | ||||
| 			completions = append( | ||||
| 				completions, | ||||
| 				a.prepareFishFlags([]Flag{HelpFlag}, command.Names())..., | ||||
| 			) | ||||
| 		} | ||||
|  | ||||
| 		*allCommands = append(*allCommands, command.Names()...) | ||||
| 		completions = append(completions, completion.String()) | ||||
| 		completions = append( | ||||
| 			completions, | ||||
| 			a.prepareFishFlags(command.Flags, command.Names())..., | ||||
| 		) | ||||
|  | ||||
| 		// recursevly iterate subcommands | ||||
| 		if len(command.Subcommands) > 0 { | ||||
| 			completions = append( | ||||
| 				completions, | ||||
| 				a.prepareFishCommands( | ||||
| 					command.Subcommands, allCommands, command.Names(), | ||||
| 				)..., | ||||
| 			) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return completions | ||||
| } | ||||
|  | ||||
| func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string { | ||||
| 	completions := []string{} | ||||
| 	for _, f := range flags { | ||||
| 		flag, ok := f.(DocGenerationFlag) | ||||
| 		if !ok { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		completion := &strings.Builder{} | ||||
| 		completion.WriteString(fmt.Sprintf( | ||||
| 			"complete -c %s -n '%s'", | ||||
| 			a.Name, | ||||
| 			a.fishSubcommandHelper(previousCommands), | ||||
| 		)) | ||||
|  | ||||
| 		fishAddFileFlag(f, completion) | ||||
|  | ||||
| 		for idx, opt := range strings.Split(flag.GetName(), ",") { | ||||
| 			if idx == 0 { | ||||
| 				completion.WriteString(fmt.Sprintf( | ||||
| 					" -l %s", strings.TrimSpace(opt), | ||||
| 				)) | ||||
| 			} else { | ||||
| 				completion.WriteString(fmt.Sprintf( | ||||
| 					" -s %s", strings.TrimSpace(opt), | ||||
| 				)) | ||||
|  | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if flag.TakesValue() { | ||||
| 			completion.WriteString(" -r") | ||||
| 		} | ||||
|  | ||||
| 		if flag.GetUsage() != "" { | ||||
| 			completion.WriteString(fmt.Sprintf(" -d '%s'", | ||||
| 				escapeSingleQuotes(flag.GetUsage()))) | ||||
| 		} | ||||
|  | ||||
| 		completions = append(completions, completion.String()) | ||||
| 	} | ||||
|  | ||||
| 	return completions | ||||
| } | ||||
|  | ||||
| func fishAddFileFlag(flag Flag, completion *strings.Builder) { | ||||
| 	switch f := flag.(type) { | ||||
| 	case GenericFlag: | ||||
| 		if f.TakesFile { | ||||
| 			return | ||||
| 		} | ||||
| 	case StringFlag: | ||||
| 		if f.TakesFile { | ||||
| 			return | ||||
| 		} | ||||
| 	case StringSliceFlag: | ||||
| 		if f.TakesFile { | ||||
| 			return | ||||
| 		} | ||||
| 	} | ||||
| 	completion.WriteString(" -f") | ||||
| } | ||||
|  | ||||
| func (a *App) fishSubcommandHelper(allCommands []string) string { | ||||
| 	fishHelper := fmt.Sprintf("__fish_%s_no_subcommand", a.Name) | ||||
| 	if len(allCommands) > 0 { | ||||
| 		fishHelper = fmt.Sprintf( | ||||
| 			"__fish_seen_subcommand_from %s", | ||||
| 			strings.Join(allCommands, " "), | ||||
| 		) | ||||
| 	} | ||||
| 	return fishHelper | ||||
|  | ||||
| } | ||||
|  | ||||
| func escapeSingleQuotes(input string) string { | ||||
| 	return strings.Replace(input, `'`, `\'`, -1) | ||||
| } | ||||
							
								
								
									
										651
									
								
								vendor/github.com/urfave/cli/flag.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										651
									
								
								vendor/github.com/urfave/cli/flag.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -3,12 +3,12 @@ package cli | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"reflect" | ||||
| 	"runtime" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"syscall" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| const defaultPlaceholder = "value" | ||||
| @@ -45,6 +45,10 @@ var FlagNamePrefixer FlagNamePrefixFunc = prefixedNames | ||||
| // details. This is used by the default FlagStringer. | ||||
| var FlagEnvHinter FlagEnvHintFunc = withEnvHint | ||||
|  | ||||
| // FlagFileHinter annotates flag help message with the environment variable | ||||
| // details. This is used by the default FlagStringer. | ||||
| var FlagFileHinter FlagFileHintFunc = withFileHint | ||||
|  | ||||
| // FlagsByName is a slice of Flag. | ||||
| type FlagsByName []Flag | ||||
|  | ||||
| @@ -53,7 +57,7 @@ func (f FlagsByName) Len() int { | ||||
| } | ||||
|  | ||||
| func (f FlagsByName) Less(i, j int) bool { | ||||
| 	return f[i].GetName() < f[j].GetName() | ||||
| 	return lexicographicLess(f[i].GetName(), f[j].GetName()) | ||||
| } | ||||
|  | ||||
| func (f FlagsByName) Swap(i, j int) { | ||||
| @@ -70,6 +74,29 @@ type Flag interface { | ||||
| 	GetName() string | ||||
| } | ||||
|  | ||||
| // RequiredFlag is an interface that allows us to mark flags as required | ||||
| // it allows flags required flags to be backwards compatible with the Flag interface | ||||
| type RequiredFlag interface { | ||||
| 	Flag | ||||
|  | ||||
| 	IsRequired() bool | ||||
| } | ||||
|  | ||||
| // DocGenerationFlag is an interface that allows documentation generation for the flag | ||||
| type DocGenerationFlag interface { | ||||
| 	Flag | ||||
|  | ||||
| 	// TakesValue returns true of the flag takes a value, otherwise false | ||||
| 	TakesValue() bool | ||||
|  | ||||
| 	// GetUsage returns the usage string for the flag | ||||
| 	GetUsage() string | ||||
|  | ||||
| 	// GetValue returns the flags value as string representation and an empty | ||||
| 	// string if the flag takes no value at all. | ||||
| 	GetValue() string | ||||
| } | ||||
|  | ||||
| // errorableFlag is an interface that allows us to return errors during apply | ||||
| // it allows flags defined in this library to return errors in a fashion backwards compatible | ||||
| // TODO remove in v2 and modify the existing Flag interface to return errors | ||||
| @@ -92,6 +119,7 @@ func flagSet(name string, flags []Flag) (*flag.FlagSet, error) { | ||||
| 			f.Apply(set) | ||||
| 		} | ||||
| 	} | ||||
| 	set.SetOutput(ioutil.Discard) | ||||
| 	return set, nil | ||||
| } | ||||
|  | ||||
| @@ -103,544 +131,12 @@ func eachName(longName string, fn func(string)) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Generic is a generic parseable type identified by a specific flag | ||||
| type Generic interface { | ||||
| 	Set(value string) error | ||||
| 	String() string | ||||
| } | ||||
|  | ||||
| // Apply takes the flagset and calls Set on the generic flag with the value | ||||
| // provided by the user for parsing by the flag | ||||
| // Ignores parsing errors | ||||
| func (f GenericFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError takes the flagset and calls Set on the generic flag with the value | ||||
| // provided by the user for parsing by the flag | ||||
| func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	val := f.Value | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				if err := val.Set(envVal); err != nil { | ||||
| 					return fmt.Errorf("could not parse %s as value for flag %s: %s", envVal, f.Name, err) | ||||
| 				} | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // StringSlice is an opaque type for []string to satisfy flag.Value and flag.Getter | ||||
| type StringSlice []string | ||||
|  | ||||
| // Set appends the string value to the list of values | ||||
| func (f *StringSlice) Set(value string) error { | ||||
| 	*f = append(*f, value) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (f *StringSlice) String() string { | ||||
| 	return fmt.Sprintf("%s", *f) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of strings set by this flag | ||||
| func (f *StringSlice) Value() []string { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Get returns the slice of strings set by this flag | ||||
| func (f *StringSlice) Get() interface{} { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f StringSliceFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				newVal := &StringSlice{} | ||||
| 				for _, s := range strings.Split(envVal, ",") { | ||||
| 					s = strings.TrimSpace(s) | ||||
| 					if err := newVal.Set(s); err != nil { | ||||
| 						return fmt.Errorf("could not parse %s as string value for flag %s: %s", envVal, f.Name, err) | ||||
| 					} | ||||
| 				} | ||||
| 				f.Value = newVal | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = &StringSlice{} | ||||
| 		} | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // IntSlice is an opaque type for []int to satisfy flag.Value and flag.Getter | ||||
| type IntSlice []int | ||||
|  | ||||
| // Set parses the value into an integer and appends it to the list of values | ||||
| func (f *IntSlice) Set(value string) error { | ||||
| 	tmp, err := strconv.Atoi(value) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	*f = append(*f, tmp) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (f *IntSlice) String() string { | ||||
| 	return fmt.Sprintf("%#v", *f) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of ints set by this flag | ||||
| func (f *IntSlice) Value() []int { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Get returns the slice of ints set by this flag | ||||
| func (f *IntSlice) Get() interface{} { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f IntSliceFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				newVal := &IntSlice{} | ||||
| 				for _, s := range strings.Split(envVal, ",") { | ||||
| 					s = strings.TrimSpace(s) | ||||
| 					if err := newVal.Set(s); err != nil { | ||||
| 						return fmt.Errorf("could not parse %s as int slice value for flag %s: %s", envVal, f.Name, err) | ||||
| 					} | ||||
| 				} | ||||
| 				f.Value = newVal | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = &IntSlice{} | ||||
| 		} | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Int64Slice is an opaque type for []int to satisfy flag.Value and flag.Getter | ||||
| type Int64Slice []int64 | ||||
|  | ||||
| // Set parses the value into an integer and appends it to the list of values | ||||
| func (f *Int64Slice) Set(value string) error { | ||||
| 	tmp, err := strconv.ParseInt(value, 10, 64) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	*f = append(*f, tmp) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (f *Int64Slice) String() string { | ||||
| 	return fmt.Sprintf("%#v", *f) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of ints set by this flag | ||||
| func (f *Int64Slice) Value() []int64 { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Get returns the slice of ints set by this flag | ||||
| func (f *Int64Slice) Get() interface{} { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f Int64SliceFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				newVal := &Int64Slice{} | ||||
| 				for _, s := range strings.Split(envVal, ",") { | ||||
| 					s = strings.TrimSpace(s) | ||||
| 					if err := newVal.Set(s); err != nil { | ||||
| 						return fmt.Errorf("could not parse %s as int64 slice value for flag %s: %s", envVal, f.Name, err) | ||||
| 					} | ||||
| 				} | ||||
| 				f.Value = newVal | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = &Int64Slice{} | ||||
| 		} | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	}) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f BoolFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	val := false | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				if envVal == "" { | ||||
| 					val = false | ||||
| 					break | ||||
| 				} | ||||
|  | ||||
| 				envValBool, err := strconv.ParseBool(envVal) | ||||
| 				if err != nil { | ||||
| 					return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) | ||||
| 				} | ||||
|  | ||||
| 				val = envValBool | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.BoolVar(f.Destination, name, val, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Bool(name, val, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f BoolTFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	val := true | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				if envVal == "" { | ||||
| 					val = false | ||||
| 					break | ||||
| 				} | ||||
|  | ||||
| 				envValBool, err := strconv.ParseBool(envVal) | ||||
| 				if err != nil { | ||||
| 					return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) | ||||
| 				} | ||||
|  | ||||
| 				val = envValBool | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.BoolVar(f.Destination, name, val, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Bool(name, val, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f StringFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f StringFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				f.Value = envVal | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.StringVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.String(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f IntFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f IntFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				envValInt, err := strconv.ParseInt(envVal, 0, 64) | ||||
| 				if err != nil { | ||||
| 					return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) | ||||
| 				} | ||||
| 				f.Value = int(envValInt) | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.IntVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Int(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f Int64Flag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				envValInt, err := strconv.ParseInt(envVal, 0, 64) | ||||
| 				if err != nil { | ||||
| 					return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) | ||||
| 				} | ||||
|  | ||||
| 				f.Value = envValInt | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.Int64Var(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Int64(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f UintFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f UintFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				envValInt, err := strconv.ParseUint(envVal, 0, 64) | ||||
| 				if err != nil { | ||||
| 					return fmt.Errorf("could not parse %s as uint value for flag %s: %s", envVal, f.Name, err) | ||||
| 				} | ||||
|  | ||||
| 				f.Value = uint(envValInt) | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.UintVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Uint(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f Uint64Flag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				envValInt, err := strconv.ParseUint(envVal, 0, 64) | ||||
| 				if err != nil { | ||||
| 					return fmt.Errorf("could not parse %s as uint64 value for flag %s: %s", envVal, f.Name, err) | ||||
| 				} | ||||
|  | ||||
| 				f.Value = uint64(envValInt) | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.Uint64Var(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Uint64(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f DurationFlag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				envValDuration, err := time.ParseDuration(envVal) | ||||
| 				if err != nil { | ||||
| 					return fmt.Errorf("could not parse %s as duration for flag %s: %s", envVal, f.Name, err) | ||||
| 				} | ||||
|  | ||||
| 				f.Value = envValDuration | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.DurationVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Duration(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f Float64Flag) Apply(set *flag.FlagSet) { | ||||
| 	f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if f.EnvVar != "" { | ||||
| 		for _, envVar := range strings.Split(f.EnvVar, ",") { | ||||
| 			envVar = strings.TrimSpace(envVar) | ||||
| 			if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 				envValFloat, err := strconv.ParseFloat(envVal, 10) | ||||
| 				if err != nil { | ||||
| 					return fmt.Errorf("could not parse %s as float64 value for flag %s: %s", envVal, f.Name, err) | ||||
| 				} | ||||
|  | ||||
| 				f.Value = float64(envValFloat) | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.Float64Var(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Float64(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func visibleFlags(fl []Flag) []Flag { | ||||
| 	visible := []Flag{} | ||||
| 	for _, flag := range fl { | ||||
| 		field := flagValue(flag).FieldByName("Hidden") | ||||
| 	var visible []Flag | ||||
| 	for _, f := range fl { | ||||
| 		field := flagValue(f).FieldByName("Hidden") | ||||
| 		if !field.IsValid() || !field.Bool() { | ||||
| 			visible = append(visible, flag) | ||||
| 			visible = append(visible, f) | ||||
| 		} | ||||
| 	} | ||||
| 	return visible | ||||
| @@ -700,11 +196,19 @@ func withEnvHint(envVar, str string) string { | ||||
| 			suffix = "%" | ||||
| 			sep = "%, %" | ||||
| 		} | ||||
| 		envText = fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(strings.Split(envVar, ","), sep), suffix) | ||||
| 		envText = " [" + prefix + strings.Join(strings.Split(envVar, ","), sep) + suffix + "]" | ||||
| 	} | ||||
| 	return str + envText | ||||
| } | ||||
|  | ||||
| func withFileHint(filePath, str string) string { | ||||
| 	fileText := "" | ||||
| 	if filePath != "" { | ||||
| 		fileText = fmt.Sprintf(" [%s]", filePath) | ||||
| 	} | ||||
| 	return str + fileText | ||||
| } | ||||
|  | ||||
| func flagValue(f Flag) reflect.Value { | ||||
| 	fv := reflect.ValueOf(f) | ||||
| 	for fv.Kind() == reflect.Ptr { | ||||
| @@ -718,14 +222,29 @@ func stringifyFlag(f Flag) string { | ||||
|  | ||||
| 	switch f.(type) { | ||||
| 	case IntSliceFlag: | ||||
| 		return FlagEnvHinter(fv.FieldByName("EnvVar").String(), | ||||
| 			stringifyIntSliceFlag(f.(IntSliceFlag))) | ||||
| 		return FlagFileHinter( | ||||
| 			fv.FieldByName("FilePath").String(), | ||||
| 			FlagEnvHinter( | ||||
| 				fv.FieldByName("EnvVar").String(), | ||||
| 				stringifyIntSliceFlag(f.(IntSliceFlag)), | ||||
| 			), | ||||
| 		) | ||||
| 	case Int64SliceFlag: | ||||
| 		return FlagEnvHinter(fv.FieldByName("EnvVar").String(), | ||||
| 			stringifyInt64SliceFlag(f.(Int64SliceFlag))) | ||||
| 		return FlagFileHinter( | ||||
| 			fv.FieldByName("FilePath").String(), | ||||
| 			FlagEnvHinter( | ||||
| 				fv.FieldByName("EnvVar").String(), | ||||
| 				stringifyInt64SliceFlag(f.(Int64SliceFlag)), | ||||
| 			), | ||||
| 		) | ||||
| 	case StringSliceFlag: | ||||
| 		return FlagEnvHinter(fv.FieldByName("EnvVar").String(), | ||||
| 			stringifyStringSliceFlag(f.(StringSliceFlag))) | ||||
| 		return FlagFileHinter( | ||||
| 			fv.FieldByName("FilePath").String(), | ||||
| 			FlagEnvHinter( | ||||
| 				fv.FieldByName("EnvVar").String(), | ||||
| 				stringifyStringSliceFlag(f.(StringSliceFlag)), | ||||
| 			), | ||||
| 		) | ||||
| 	} | ||||
|  | ||||
| 	placeholder, usage := unquoteUsage(fv.FieldByName("Usage").String()) | ||||
| @@ -750,17 +269,22 @@ func stringifyFlag(f Flag) string { | ||||
| 		placeholder = defaultPlaceholder | ||||
| 	} | ||||
|  | ||||
| 	usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultValueString)) | ||||
| 	usageWithDefault := strings.TrimSpace(usage + defaultValueString) | ||||
|  | ||||
| 	return FlagEnvHinter(fv.FieldByName("EnvVar").String(), | ||||
| 		fmt.Sprintf("%s\t%s", FlagNamePrefixer(fv.FieldByName("Name").String(), placeholder), usageWithDefault)) | ||||
| 	return FlagFileHinter( | ||||
| 		fv.FieldByName("FilePath").String(), | ||||
| 		FlagEnvHinter( | ||||
| 			fv.FieldByName("EnvVar").String(), | ||||
| 			FlagNamePrefixer(fv.FieldByName("Name").String(), placeholder)+"\t"+usageWithDefault, | ||||
| 		), | ||||
| 	) | ||||
| } | ||||
|  | ||||
| func stringifyIntSliceFlag(f IntSliceFlag) string { | ||||
| 	defaultVals := []string{} | ||||
| 	var defaultVals []string | ||||
| 	if f.Value != nil && len(f.Value.Value()) > 0 { | ||||
| 		for _, i := range f.Value.Value() { | ||||
| 			defaultVals = append(defaultVals, fmt.Sprintf("%d", i)) | ||||
| 			defaultVals = append(defaultVals, strconv.Itoa(i)) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -768,10 +292,10 @@ func stringifyIntSliceFlag(f IntSliceFlag) string { | ||||
| } | ||||
|  | ||||
| func stringifyInt64SliceFlag(f Int64SliceFlag) string { | ||||
| 	defaultVals := []string{} | ||||
| 	var defaultVals []string | ||||
| 	if f.Value != nil && len(f.Value.Value()) > 0 { | ||||
| 		for _, i := range f.Value.Value() { | ||||
| 			defaultVals = append(defaultVals, fmt.Sprintf("%d", i)) | ||||
| 			defaultVals = append(defaultVals, strconv.FormatInt(i, 10)) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -779,11 +303,11 @@ func stringifyInt64SliceFlag(f Int64SliceFlag) string { | ||||
| } | ||||
|  | ||||
| func stringifyStringSliceFlag(f StringSliceFlag) string { | ||||
| 	defaultVals := []string{} | ||||
| 	var defaultVals []string | ||||
| 	if f.Value != nil && len(f.Value.Value()) > 0 { | ||||
| 		for _, s := range f.Value.Value() { | ||||
| 			if len(s) > 0 { | ||||
| 				defaultVals = append(defaultVals, fmt.Sprintf("%q", s)) | ||||
| 				defaultVals = append(defaultVals, strconv.Quote(s)) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| @@ -802,6 +326,21 @@ func stringifySliceFlag(usage, name string, defaultVals []string) string { | ||||
| 		defaultVal = fmt.Sprintf(" (default: %s)", strings.Join(defaultVals, ", ")) | ||||
| 	} | ||||
|  | ||||
| 	usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultVal)) | ||||
| 	return fmt.Sprintf("%s\t%s", FlagNamePrefixer(name, placeholder), usageWithDefault) | ||||
| 	usageWithDefault := strings.TrimSpace(usage + defaultVal) | ||||
| 	return FlagNamePrefixer(name, placeholder) + "\t" + usageWithDefault | ||||
| } | ||||
|  | ||||
| func flagFromFileEnv(filePath, envName string) (val string, ok bool) { | ||||
| 	for _, envVar := range strings.Split(envName, ",") { | ||||
| 		envVar = strings.TrimSpace(envVar) | ||||
| 		if envVal, ok := syscall.Getenv(envVar); ok { | ||||
| 			return envVal, true | ||||
| 		} | ||||
| 	} | ||||
| 	for _, fileVar := range strings.Split(filePath, ",") { | ||||
| 		if data, err := ioutil.ReadFile(fileVar); err == nil { | ||||
| 			return string(data), true | ||||
| 		} | ||||
| 	} | ||||
| 	return "", false | ||||
| } | ||||
|   | ||||
							
								
								
									
										109
									
								
								vendor/github.com/urfave/cli/flag_bool.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								vendor/github.com/urfave/cli/flag_bool.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,109 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // BoolFlag is a flag with type bool | ||||
| type BoolFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Destination *bool | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f BoolFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f BoolFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f BoolFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f BoolFlag) TakesValue() bool { | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f BoolFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f BoolFlag) GetValue() string { | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| // Bool looks up the value of a local BoolFlag, returns | ||||
| // false if not found | ||||
| func (c *Context) Bool(name string) bool { | ||||
| 	return lookupBool(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalBool looks up the value of a global BoolFlag, returns | ||||
| // false if not found | ||||
| func (c *Context) GlobalBool(name string) bool { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupBool(name, fs) | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f BoolFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	val := false | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		if envVal == "" { | ||||
| 			val = false | ||||
| 		} else { | ||||
| 			envValBool, err := strconv.ParseBool(envVal) | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) | ||||
| 			} | ||||
| 			val = envValBool | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.BoolVar(f.Destination, name, val, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Bool(name, val, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupBool(name string, set *flag.FlagSet) bool { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseBool(f.Value.String()) | ||||
| 		if err != nil { | ||||
| 			return false | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
							
								
								
									
										110
									
								
								vendor/github.com/urfave/cli/flag_bool_t.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								vendor/github.com/urfave/cli/flag_bool_t.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,110 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // BoolTFlag is a flag with type bool that is true by default | ||||
| type BoolTFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Destination *bool | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f BoolTFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f BoolTFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f BoolTFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f BoolTFlag) TakesValue() bool { | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f BoolTFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f BoolTFlag) GetValue() string { | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| // BoolT looks up the value of a local BoolTFlag, returns | ||||
| // false if not found | ||||
| func (c *Context) BoolT(name string) bool { | ||||
| 	return lookupBoolT(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalBoolT looks up the value of a global BoolTFlag, returns | ||||
| // false if not found | ||||
| func (c *Context) GlobalBoolT(name string) bool { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupBoolT(name, fs) | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f BoolTFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	val := true | ||||
|  | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		if envVal == "" { | ||||
| 			val = false | ||||
| 		} else { | ||||
| 			envValBool, err := strconv.ParseBool(envVal) | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) | ||||
| 			} | ||||
| 			val = envValBool | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.BoolVar(f.Destination, name, val, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Bool(name, val, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupBoolT(name string, set *flag.FlagSet) bool { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseBool(f.Value.String()) | ||||
| 		if err != nil { | ||||
| 			return false | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
							
								
								
									
										106
									
								
								vendor/github.com/urfave/cli/flag_duration.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								vendor/github.com/urfave/cli/flag_duration.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| // DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration) | ||||
| type DurationFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       time.Duration | ||||
| 	Destination *time.Duration | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f DurationFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f DurationFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f DurationFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f DurationFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f DurationFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f DurationFlag) GetValue() string { | ||||
| 	return f.Value.String() | ||||
| } | ||||
|  | ||||
| // Duration looks up the value of a local DurationFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Duration(name string) time.Duration { | ||||
| 	return lookupDuration(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalDuration looks up the value of a global DurationFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalDuration(name string) time.Duration { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupDuration(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f DurationFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		envValDuration, err := time.ParseDuration(envVal) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("could not parse %s as duration for flag %s: %s", envVal, f.Name, err) | ||||
| 		} | ||||
|  | ||||
| 		f.Value = envValDuration | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.DurationVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Duration(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupDuration(name string, set *flag.FlagSet) time.Duration { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := time.ParseDuration(f.Value.String()) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
							
								
								
									
										106
									
								
								vendor/github.com/urfave/cli/flag_float64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								vendor/github.com/urfave/cli/flag_float64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // Float64Flag is a flag with type float64 | ||||
| type Float64Flag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       float64 | ||||
| 	Destination *float64 | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f Float64Flag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f Float64Flag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f Float64Flag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f Float64Flag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f Float64Flag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f Float64Flag) GetValue() string { | ||||
| 	return fmt.Sprintf("%f", f.Value) | ||||
| } | ||||
|  | ||||
| // Float64 looks up the value of a local Float64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Float64(name string) float64 { | ||||
| 	return lookupFloat64(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalFloat64 looks up the value of a global Float64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalFloat64(name string) float64 { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupFloat64(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f Float64Flag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		envValFloat, err := strconv.ParseFloat(envVal, 10) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("could not parse %s as float64 value for flag %s: %s", envVal, f.Name, err) | ||||
| 		} | ||||
|  | ||||
| 		f.Value = envValFloat | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.Float64Var(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Float64(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupFloat64(name string, set *flag.FlagSet) float64 { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseFloat(f.Value.String(), 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
							
								
								
									
										627
									
								
								vendor/github.com/urfave/cli/flag_generated.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										627
									
								
								vendor/github.com/urfave/cli/flag_generated.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,627 +0,0 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"strconv" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| // WARNING: This file is generated! | ||||
|  | ||||
| // BoolFlag is a flag with type bool | ||||
| type BoolFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	Hidden      bool | ||||
| 	Destination *bool | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f BoolFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f BoolFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // Bool looks up the value of a local BoolFlag, returns | ||||
| // false if not found | ||||
| func (c *Context) Bool(name string) bool { | ||||
| 	return lookupBool(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalBool looks up the value of a global BoolFlag, returns | ||||
| // false if not found | ||||
| func (c *Context) GlobalBool(name string) bool { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupBool(name, fs) | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| func lookupBool(name string, set *flag.FlagSet) bool { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseBool(f.Value.String()) | ||||
| 		if err != nil { | ||||
| 			return false | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // BoolTFlag is a flag with type bool that is true by default | ||||
| type BoolTFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	Hidden      bool | ||||
| 	Destination *bool | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f BoolTFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f BoolTFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // BoolT looks up the value of a local BoolTFlag, returns | ||||
| // false if not found | ||||
| func (c *Context) BoolT(name string) bool { | ||||
| 	return lookupBoolT(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalBoolT looks up the value of a global BoolTFlag, returns | ||||
| // false if not found | ||||
| func (c *Context) GlobalBoolT(name string) bool { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupBoolT(name, fs) | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| func lookupBoolT(name string, set *flag.FlagSet) bool { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseBool(f.Value.String()) | ||||
| 		if err != nil { | ||||
| 			return false | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration) | ||||
| type DurationFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	Hidden      bool | ||||
| 	Value       time.Duration | ||||
| 	Destination *time.Duration | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f DurationFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f DurationFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // Duration looks up the value of a local DurationFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Duration(name string) time.Duration { | ||||
| 	return lookupDuration(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalDuration looks up the value of a global DurationFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalDuration(name string) time.Duration { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupDuration(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupDuration(name string, set *flag.FlagSet) time.Duration { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := time.ParseDuration(f.Value.String()) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| // Float64Flag is a flag with type float64 | ||||
| type Float64Flag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	Hidden      bool | ||||
| 	Value       float64 | ||||
| 	Destination *float64 | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f Float64Flag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f Float64Flag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // Float64 looks up the value of a local Float64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Float64(name string) float64 { | ||||
| 	return lookupFloat64(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalFloat64 looks up the value of a global Float64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalFloat64(name string) float64 { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupFloat64(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupFloat64(name string, set *flag.FlagSet) float64 { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseFloat(f.Value.String(), 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| // GenericFlag is a flag with type Generic | ||||
| type GenericFlag struct { | ||||
| 	Name   string | ||||
| 	Usage  string | ||||
| 	EnvVar string | ||||
| 	Hidden bool | ||||
| 	Value  Generic | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f GenericFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f GenericFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // Generic looks up the value of a local GenericFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) Generic(name string) interface{} { | ||||
| 	return lookupGeneric(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalGeneric looks up the value of a global GenericFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) GlobalGeneric(name string) interface{} { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupGeneric(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupGeneric(name string, set *flag.FlagSet) interface{} { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := f.Value, error(nil) | ||||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Int64Flag is a flag with type int64 | ||||
| type Int64Flag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	Hidden      bool | ||||
| 	Value       int64 | ||||
| 	Destination *int64 | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f Int64Flag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f Int64Flag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // Int64 looks up the value of a local Int64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Int64(name string) int64 { | ||||
| 	return lookupInt64(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalInt64 looks up the value of a global Int64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalInt64(name string) int64 { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupInt64(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupInt64(name string, set *flag.FlagSet) int64 { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| // IntFlag is a flag with type int | ||||
| type IntFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	Hidden      bool | ||||
| 	Value       int | ||||
| 	Destination *int | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f IntFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f IntFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // Int looks up the value of a local IntFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Int(name string) int { | ||||
| 	return lookupInt(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalInt looks up the value of a global IntFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalInt(name string) int { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupInt(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupInt(name string, set *flag.FlagSet) int { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return int(parsed) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| // IntSliceFlag is a flag with type *IntSlice | ||||
| type IntSliceFlag struct { | ||||
| 	Name   string | ||||
| 	Usage  string | ||||
| 	EnvVar string | ||||
| 	Hidden bool | ||||
| 	Value  *IntSlice | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f IntSliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f IntSliceFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IntSlice looks up the value of a local IntSliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) IntSlice(name string) []int { | ||||
| 	return lookupIntSlice(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalIntSlice looks up the value of a global IntSliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) GlobalIntSlice(name string) []int { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupIntSlice(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupIntSlice(name string, set *flag.FlagSet) []int { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := (f.Value.(*IntSlice)).Value(), error(nil) | ||||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Int64SliceFlag is a flag with type *Int64Slice | ||||
| type Int64SliceFlag struct { | ||||
| 	Name   string | ||||
| 	Usage  string | ||||
| 	EnvVar string | ||||
| 	Hidden bool | ||||
| 	Value  *Int64Slice | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f Int64SliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f Int64SliceFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // Int64Slice looks up the value of a local Int64SliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) Int64Slice(name string) []int64 { | ||||
| 	return lookupInt64Slice(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) GlobalInt64Slice(name string) []int64 { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupInt64Slice(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupInt64Slice(name string, set *flag.FlagSet) []int64 { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil) | ||||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // StringFlag is a flag with type string | ||||
| type StringFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	Hidden      bool | ||||
| 	Value       string | ||||
| 	Destination *string | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f StringFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f StringFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // String looks up the value of a local StringFlag, returns | ||||
| // "" if not found | ||||
| func (c *Context) String(name string) string { | ||||
| 	return lookupString(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalString looks up the value of a global StringFlag, returns | ||||
| // "" if not found | ||||
| func (c *Context) GlobalString(name string) string { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupString(name, fs) | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| func lookupString(name string, set *flag.FlagSet) string { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := f.Value.String(), error(nil) | ||||
| 		if err != nil { | ||||
| 			return "" | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| // StringSliceFlag is a flag with type *StringSlice | ||||
| type StringSliceFlag struct { | ||||
| 	Name   string | ||||
| 	Usage  string | ||||
| 	EnvVar string | ||||
| 	Hidden bool | ||||
| 	Value  *StringSlice | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f StringSliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f StringSliceFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // StringSlice looks up the value of a local StringSliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) StringSlice(name string) []string { | ||||
| 	return lookupStringSlice(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalStringSlice looks up the value of a global StringSliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) GlobalStringSlice(name string) []string { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupStringSlice(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupStringSlice(name string, set *flag.FlagSet) []string { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := (f.Value.(*StringSlice)).Value(), error(nil) | ||||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Uint64Flag is a flag with type uint64 | ||||
| type Uint64Flag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	Hidden      bool | ||||
| 	Value       uint64 | ||||
| 	Destination *uint64 | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f Uint64Flag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f Uint64Flag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // Uint64 looks up the value of a local Uint64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Uint64(name string) uint64 { | ||||
| 	return lookupUint64(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalUint64 looks up the value of a global Uint64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalUint64(name string) uint64 { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupUint64(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupUint64(name string, set *flag.FlagSet) uint64 { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| // UintFlag is a flag with type uint | ||||
| type UintFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	Hidden      bool | ||||
| 	Value       uint | ||||
| 	Destination *uint | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f UintFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f UintFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // Uint looks up the value of a local UintFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Uint(name string) uint { | ||||
| 	return lookupUint(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalUint looks up the value of a global UintFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalUint(name string) uint { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupUint(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupUint(name string, set *flag.FlagSet) uint { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return uint(parsed) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
							
								
								
									
										110
									
								
								vendor/github.com/urfave/cli/flag_generic.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								vendor/github.com/urfave/cli/flag_generic.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,110 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| ) | ||||
|  | ||||
| // Generic is a generic parseable type identified by a specific flag | ||||
| type Generic interface { | ||||
| 	Set(value string) error | ||||
| 	String() string | ||||
| } | ||||
|  | ||||
| // GenericFlag is a flag with type Generic | ||||
| type GenericFlag struct { | ||||
| 	Name      string | ||||
| 	Usage     string | ||||
| 	EnvVar    string | ||||
| 	FilePath  string | ||||
| 	Required  bool | ||||
| 	Hidden    bool | ||||
| 	TakesFile bool | ||||
| 	Value     Generic | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f GenericFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f GenericFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f GenericFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f GenericFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f GenericFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f GenericFlag) GetValue() string { | ||||
| 	if f.Value != nil { | ||||
| 		return f.Value.String() | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| // Apply takes the flagset and calls Set on the generic flag with the value | ||||
| // provided by the user for parsing by the flag | ||||
| // Ignores parsing errors | ||||
| func (f GenericFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError takes the flagset and calls Set on the generic flag with the value | ||||
| // provided by the user for parsing by the flag | ||||
| func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	val := f.Value | ||||
| 	if fileEnvVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		if err := val.Set(fileEnvVal); err != nil { | ||||
| 			return fmt.Errorf("could not parse %s as value for flag %s: %s", fileEnvVal, f.Name, err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Generic looks up the value of a local GenericFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) Generic(name string) interface{} { | ||||
| 	return lookupGeneric(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalGeneric looks up the value of a global GenericFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) GlobalGeneric(name string) interface{} { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupGeneric(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupGeneric(name string, set *flag.FlagSet) interface{} { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := f.Value, error(nil) | ||||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										105
									
								
								vendor/github.com/urfave/cli/flag_int.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								vendor/github.com/urfave/cli/flag_int.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // IntFlag is a flag with type int | ||||
| type IntFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       int | ||||
| 	Destination *int | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f IntFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f IntFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f IntFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f IntFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f IntFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f IntFlag) GetValue() string { | ||||
| 	return fmt.Sprintf("%d", f.Value) | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f IntFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f IntFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		envValInt, err := strconv.ParseInt(envVal, 0, 64) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) | ||||
| 		} | ||||
| 		f.Value = int(envValInt) | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.IntVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Int(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Int looks up the value of a local IntFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Int(name string) int { | ||||
| 	return lookupInt(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalInt looks up the value of a global IntFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalInt(name string) int { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupInt(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupInt(name string, set *flag.FlagSet) int { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return int(parsed) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
							
								
								
									
										106
									
								
								vendor/github.com/urfave/cli/flag_int64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								vendor/github.com/urfave/cli/flag_int64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // Int64Flag is a flag with type int64 | ||||
| type Int64Flag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       int64 | ||||
| 	Destination *int64 | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f Int64Flag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f Int64Flag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f Int64Flag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f Int64Flag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f Int64Flag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f Int64Flag) GetValue() string { | ||||
| 	return fmt.Sprintf("%d", f.Value) | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f Int64Flag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		envValInt, err := strconv.ParseInt(envVal, 0, 64) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) | ||||
| 		} | ||||
|  | ||||
| 		f.Value = envValInt | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.Int64Var(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Int64(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Int64 looks up the value of a local Int64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Int64(name string) int64 { | ||||
| 	return lookupInt64(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalInt64 looks up the value of a global Int64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalInt64(name string) int64 { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupInt64(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupInt64(name string, set *flag.FlagSet) int64 { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
							
								
								
									
										141
									
								
								vendor/github.com/urfave/cli/flag_int64_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								vendor/github.com/urfave/cli/flag_int64_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,141 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // Int64Slice is an opaque type for []int to satisfy flag.Value and flag.Getter | ||||
| type Int64Slice []int64 | ||||
|  | ||||
| // Set parses the value into an integer and appends it to the list of values | ||||
| func (f *Int64Slice) Set(value string) error { | ||||
| 	tmp, err := strconv.ParseInt(value, 10, 64) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	*f = append(*f, tmp) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (f *Int64Slice) String() string { | ||||
| 	return fmt.Sprintf("%#v", *f) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of ints set by this flag | ||||
| func (f *Int64Slice) Value() []int64 { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Get returns the slice of ints set by this flag | ||||
| func (f *Int64Slice) Get() interface{} { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Int64SliceFlag is a flag with type *Int64Slice | ||||
| type Int64SliceFlag struct { | ||||
| 	Name     string | ||||
| 	Usage    string | ||||
| 	EnvVar   string | ||||
| 	FilePath string | ||||
| 	Required bool | ||||
| 	Hidden   bool | ||||
| 	Value    *Int64Slice | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f Int64SliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f Int64SliceFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f Int64SliceFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f Int64SliceFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f Int64SliceFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f Int64SliceFlag) GetValue() string { | ||||
| 	if f.Value != nil { | ||||
| 		return f.Value.String() | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f Int64SliceFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		newVal := &Int64Slice{} | ||||
| 		for _, s := range strings.Split(envVal, ",") { | ||||
| 			s = strings.TrimSpace(s) | ||||
| 			if err := newVal.Set(s); err != nil { | ||||
| 				return fmt.Errorf("could not parse %s as int64 slice value for flag %s: %s", envVal, f.Name, err) | ||||
| 			} | ||||
| 		} | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = newVal | ||||
| 		} else { | ||||
| 			*f.Value = *newVal | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = &Int64Slice{} | ||||
| 		} | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	}) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Int64Slice looks up the value of a local Int64SliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) Int64Slice(name string) []int64 { | ||||
| 	return lookupInt64Slice(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) GlobalInt64Slice(name string) []int64 { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupInt64Slice(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupInt64Slice(name string, set *flag.FlagSet) []int64 { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil) | ||||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										142
									
								
								vendor/github.com/urfave/cli/flag_int_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								vendor/github.com/urfave/cli/flag_int_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,142 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // IntSlice is an opaque type for []int to satisfy flag.Value and flag.Getter | ||||
| type IntSlice []int | ||||
|  | ||||
| // Set parses the value into an integer and appends it to the list of values | ||||
| func (f *IntSlice) Set(value string) error { | ||||
| 	tmp, err := strconv.Atoi(value) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	*f = append(*f, tmp) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (f *IntSlice) String() string { | ||||
| 	return fmt.Sprintf("%#v", *f) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of ints set by this flag | ||||
| func (f *IntSlice) Value() []int { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Get returns the slice of ints set by this flag | ||||
| func (f *IntSlice) Get() interface{} { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // IntSliceFlag is a flag with type *IntSlice | ||||
| type IntSliceFlag struct { | ||||
| 	Name     string | ||||
| 	Usage    string | ||||
| 	EnvVar   string | ||||
| 	FilePath string | ||||
| 	Required bool | ||||
| 	Hidden   bool | ||||
| 	Value    *IntSlice | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f IntSliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f IntSliceFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f IntSliceFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f IntSliceFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f IntSliceFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f IntSliceFlag) GetValue() string { | ||||
| 	if f.Value != nil { | ||||
| 		return f.Value.String() | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f IntSliceFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		newVal := &IntSlice{} | ||||
| 		for _, s := range strings.Split(envVal, ",") { | ||||
| 			s = strings.TrimSpace(s) | ||||
| 			if err := newVal.Set(s); err != nil { | ||||
| 				return fmt.Errorf("could not parse %s as int slice value for flag %s: %s", envVal, f.Name, err) | ||||
| 			} | ||||
| 		} | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = newVal | ||||
| 		} else { | ||||
| 			*f.Value = *newVal | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = &IntSlice{} | ||||
| 		} | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // IntSlice looks up the value of a local IntSliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) IntSlice(name string) []int { | ||||
| 	return lookupIntSlice(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalIntSlice looks up the value of a global IntSliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) GlobalIntSlice(name string) []int { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupIntSlice(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupIntSlice(name string, set *flag.FlagSet) []int { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := (f.Value.(*IntSlice)).Value(), error(nil) | ||||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										98
									
								
								vendor/github.com/urfave/cli/flag_string.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								vendor/github.com/urfave/cli/flag_string.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,98 @@ | ||||
| package cli | ||||
|  | ||||
| import "flag" | ||||
|  | ||||
| // StringFlag is a flag with type string | ||||
| type StringFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	TakesFile   bool | ||||
| 	Value       string | ||||
| 	Destination *string | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f StringFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f StringFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f StringFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f StringFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f StringFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f StringFlag) GetValue() string { | ||||
| 	return f.Value | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f StringFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f StringFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		f.Value = envVal | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.StringVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.String(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String looks up the value of a local StringFlag, returns | ||||
| // "" if not found | ||||
| func (c *Context) String(name string) string { | ||||
| 	return lookupString(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalString looks up the value of a global StringFlag, returns | ||||
| // "" if not found | ||||
| func (c *Context) GlobalString(name string) string { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupString(name, fs) | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| func lookupString(name string, set *flag.FlagSet) string { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := f.Value.String(), error(nil) | ||||
| 		if err != nil { | ||||
| 			return "" | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
							
								
								
									
										138
									
								
								vendor/github.com/urfave/cli/flag_string_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								vendor/github.com/urfave/cli/flag_string_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,138 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // StringSlice is an opaque type for []string to satisfy flag.Value and flag.Getter | ||||
| type StringSlice []string | ||||
|  | ||||
| // Set appends the string value to the list of values | ||||
| func (f *StringSlice) Set(value string) error { | ||||
| 	*f = append(*f, value) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (f *StringSlice) String() string { | ||||
| 	return fmt.Sprintf("%s", *f) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of strings set by this flag | ||||
| func (f *StringSlice) Value() []string { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Get returns the slice of strings set by this flag | ||||
| func (f *StringSlice) Get() interface{} { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // StringSliceFlag is a flag with type *StringSlice | ||||
| type StringSliceFlag struct { | ||||
| 	Name      string | ||||
| 	Usage     string | ||||
| 	EnvVar    string | ||||
| 	FilePath  string | ||||
| 	Required  bool | ||||
| 	Hidden    bool | ||||
| 	TakesFile bool | ||||
| 	Value     *StringSlice | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f StringSliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f StringSliceFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f StringSliceFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f StringSliceFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f StringSliceFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f StringSliceFlag) GetValue() string { | ||||
| 	if f.Value != nil { | ||||
| 		return f.Value.String() | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f StringSliceFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		newVal := &StringSlice{} | ||||
| 		for _, s := range strings.Split(envVal, ",") { | ||||
| 			s = strings.TrimSpace(s) | ||||
| 			if err := newVal.Set(s); err != nil { | ||||
| 				return fmt.Errorf("could not parse %s as string value for flag %s: %s", envVal, f.Name, err) | ||||
| 			} | ||||
| 		} | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = newVal | ||||
| 		} else { | ||||
| 			*f.Value = *newVal | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = &StringSlice{} | ||||
| 		} | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // StringSlice looks up the value of a local StringSliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) StringSlice(name string) []string { | ||||
| 	return lookupStringSlice(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalStringSlice looks up the value of a global StringSliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) GlobalStringSlice(name string) []string { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupStringSlice(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupStringSlice(name string, set *flag.FlagSet) []string { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := (f.Value.(*StringSlice)).Value(), error(nil) | ||||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										106
									
								
								vendor/github.com/urfave/cli/flag_uint.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								vendor/github.com/urfave/cli/flag_uint.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // UintFlag is a flag with type uint | ||||
| type UintFlag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       uint | ||||
| 	Destination *uint | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f UintFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f UintFlag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f UintFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f UintFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f UintFlag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f UintFlag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f UintFlag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		envValInt, err := strconv.ParseUint(envVal, 0, 64) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("could not parse %s as uint value for flag %s: %s", envVal, f.Name, err) | ||||
| 		} | ||||
|  | ||||
| 		f.Value = uint(envValInt) | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.UintVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Uint(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f UintFlag) GetValue() string { | ||||
| 	return fmt.Sprintf("%d", f.Value) | ||||
| } | ||||
|  | ||||
| // Uint looks up the value of a local UintFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Uint(name string) uint { | ||||
| 	return lookupUint(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalUint looks up the value of a global UintFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalUint(name string) uint { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupUint(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupUint(name string, set *flag.FlagSet) uint { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return uint(parsed) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
							
								
								
									
										106
									
								
								vendor/github.com/urfave/cli/flag_uint64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								vendor/github.com/urfave/cli/flag_uint64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // Uint64Flag is a flag with type uint64 | ||||
| type Uint64Flag struct { | ||||
| 	Name        string | ||||
| 	Usage       string | ||||
| 	EnvVar      string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       uint64 | ||||
| 	Destination *uint64 | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f Uint64Flag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // GetName returns the name of the flag | ||||
| func (f Uint64Flag) GetName() string { | ||||
| 	return f.Name | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f Uint64Flag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f Uint64Flag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f Uint64Flag) GetUsage() string { | ||||
| 	return f.Usage | ||||
| } | ||||
|  | ||||
| // GetValue returns the flags value as string representation and an empty | ||||
| // string if the flag takes no value at all. | ||||
| func (f Uint64Flag) GetValue() string { | ||||
| 	return fmt.Sprintf("%d", f.Value) | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| // Ignores errors | ||||
| func (f Uint64Flag) Apply(set *flag.FlagSet) { | ||||
| 	_ = f.ApplyWithError(set) | ||||
| } | ||||
|  | ||||
| // ApplyWithError populates the flag given the flag set and environment | ||||
| func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error { | ||||
| 	if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { | ||||
| 		envValInt, err := strconv.ParseUint(envVal, 0, 64) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("could not parse %s as uint64 value for flag %s: %s", envVal, f.Name, err) | ||||
| 		} | ||||
|  | ||||
| 		f.Value = envValInt | ||||
| 	} | ||||
|  | ||||
| 	eachName(f.Name, func(name string) { | ||||
| 		if f.Destination != nil { | ||||
| 			set.Uint64Var(f.Destination, name, f.Value, f.Usage) | ||||
| 			return | ||||
| 		} | ||||
| 		set.Uint64(name, f.Value, f.Usage) | ||||
| 	}) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Uint64 looks up the value of a local Uint64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Uint64(name string) uint64 { | ||||
| 	return lookupUint64(name, c.flagSet) | ||||
| } | ||||
|  | ||||
| // GlobalUint64 looks up the value of a global Uint64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) GlobalUint64(name string) uint64 { | ||||
| 	if fs := lookupGlobalFlagSet(name, c); fs != nil { | ||||
| 		return lookupUint64(name, fs) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func lookupUint64(name string, set *flag.FlagSet) uint64 { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) | ||||
| 		if err != nil { | ||||
| 			return 0 | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
							
								
								
									
										3
									
								
								vendor/github.com/urfave/cli/funcs.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								vendor/github.com/urfave/cli/funcs.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -39,3 +39,6 @@ type FlagNamePrefixFunc func(fullName, placeholder string) string | ||||
| // with the environment variable details. | ||||
| type FlagEnvHintFunc func(envVar, str string) string | ||||
|  | ||||
| // FlagFileHintFunc is used by the default FlagStringFunc to annotate flag help | ||||
| // with the file path details. | ||||
| type FlagFileHintFunc func(filePath, str string) string | ||||
|   | ||||
							
								
								
									
										9
									
								
								vendor/github.com/urfave/cli/go.mod
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								vendor/github.com/urfave/cli/go.mod
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| module github.com/urfave/cli | ||||
|  | ||||
| go 1.11 | ||||
|  | ||||
| require ( | ||||
| 	github.com/BurntSushi/toml v0.3.1 | ||||
| 	github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d | ||||
| 	gopkg.in/yaml.v2 v2.2.2 | ||||
| ) | ||||
							
								
								
									
										183
									
								
								vendor/github.com/urfave/cli/help.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										183
									
								
								vendor/github.com/urfave/cli/help.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -7,78 +7,9 @@ import ( | ||||
| 	"strings" | ||||
| 	"text/tabwriter" | ||||
| 	"text/template" | ||||
| 	"unicode/utf8" | ||||
| ) | ||||
|  | ||||
| // AppHelpTemplate is the text template for the Default help topic. | ||||
| // cli.go uses text/template to render templates. You can | ||||
| // render custom help text by setting this variable. | ||||
| var AppHelpTemplate = `NAME: | ||||
|    {{.Name}}{{if .Usage}} - {{.Usage}}{{end}} | ||||
|  | ||||
| USAGE: | ||||
|    {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} | ||||
|  | ||||
| VERSION: | ||||
|    {{.Version}}{{end}}{{end}}{{if .Description}} | ||||
|  | ||||
| DESCRIPTION: | ||||
|    {{.Description}}{{end}}{{if len .Authors}} | ||||
|  | ||||
| AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: | ||||
|    {{range $index, $author := .Authors}}{{if $index}} | ||||
|    {{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}} | ||||
|  | ||||
| COMMANDS:{{range .VisibleCategories}}{{if .Name}} | ||||
|  | ||||
|    {{.Name}}:{{end}}{{range .VisibleCommands}} | ||||
|      {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} | ||||
|  | ||||
| GLOBAL OPTIONS: | ||||
|    {{range $index, $option := .VisibleFlags}}{{if $index}} | ||||
|    {{end}}{{$option}}{{end}}{{end}}{{if .Copyright}} | ||||
|  | ||||
| COPYRIGHT: | ||||
|    {{.Copyright}}{{end}} | ||||
| ` | ||||
|  | ||||
| // CommandHelpTemplate is the text template for the command help topic. | ||||
| // cli.go uses text/template to render templates. You can | ||||
| // render custom help text by setting this variable. | ||||
| var CommandHelpTemplate = `NAME: | ||||
|    {{.HelpName}} - {{.Usage}} | ||||
|  | ||||
| USAGE: | ||||
|    {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}} | ||||
|  | ||||
| CATEGORY: | ||||
|    {{.Category}}{{end}}{{if .Description}} | ||||
|  | ||||
| DESCRIPTION: | ||||
|    {{.Description}}{{end}}{{if .VisibleFlags}} | ||||
|  | ||||
| OPTIONS: | ||||
|    {{range .VisibleFlags}}{{.}} | ||||
|    {{end}}{{end}} | ||||
| ` | ||||
|  | ||||
| // SubcommandHelpTemplate is the text template for the subcommand help topic. | ||||
| // cli.go uses text/template to render templates. You can | ||||
| // render custom help text by setting this variable. | ||||
| var SubcommandHelpTemplate = `NAME: | ||||
|    {{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}} | ||||
|  | ||||
| USAGE: | ||||
|    {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} | ||||
|  | ||||
| COMMANDS:{{range .VisibleCategories}}{{if .Name}} | ||||
|    {{.Name}}:{{end}}{{range .VisibleCommands}} | ||||
|      {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}} | ||||
| {{end}}{{if .VisibleFlags}} | ||||
| OPTIONS: | ||||
|    {{range .VisibleFlags}}{{.}} | ||||
|    {{end}}{{end}} | ||||
| ` | ||||
|  | ||||
| var helpCommand = Command{ | ||||
| 	Name:      "help", | ||||
| 	Aliases:   []string{"h"}, | ||||
| @@ -90,7 +21,7 @@ var helpCommand = Command{ | ||||
| 			return ShowCommandHelp(c, args.First()) | ||||
| 		} | ||||
|  | ||||
| 		ShowAppHelp(c) | ||||
| 		_ = ShowAppHelp(c) | ||||
| 		return nil | ||||
| 	}, | ||||
| } | ||||
| @@ -130,7 +61,7 @@ var VersionPrinter = printVersion | ||||
|  | ||||
| // ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code. | ||||
| func ShowAppHelpAndExit(c *Context, exitCode int) { | ||||
| 	ShowAppHelp(c) | ||||
| 	_ = ShowAppHelp(c) | ||||
| 	os.Exit(exitCode) | ||||
| } | ||||
|  | ||||
| @@ -154,19 +85,94 @@ func ShowAppHelp(c *Context) (err error) { | ||||
|  | ||||
| // DefaultAppComplete prints the list of subcommands as the default app completion method | ||||
| func DefaultAppComplete(c *Context) { | ||||
| 	for _, command := range c.App.Commands { | ||||
| 	DefaultCompleteWithFlags(nil)(c) | ||||
| } | ||||
|  | ||||
| func printCommandSuggestions(commands []Command, writer io.Writer) { | ||||
| 	for _, command := range commands { | ||||
| 		if command.Hidden { | ||||
| 			continue | ||||
| 		} | ||||
| 		for _, name := range command.Names() { | ||||
| 			fmt.Fprintln(c.App.Writer, name) | ||||
| 		if os.Getenv("_CLI_ZSH_AUTOCOMPLETE_HACK") == "1" { | ||||
| 			for _, name := range command.Names() { | ||||
| 				_, _ = fmt.Fprintf(writer, "%s:%s\n", name, command.Usage) | ||||
| 			} | ||||
| 		} else { | ||||
| 			for _, name := range command.Names() { | ||||
| 				_, _ = fmt.Fprintf(writer, "%s\n", name) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func cliArgContains(flagName string) bool { | ||||
| 	for _, name := range strings.Split(flagName, ",") { | ||||
| 		name = strings.TrimSpace(name) | ||||
| 		count := utf8.RuneCountInString(name) | ||||
| 		if count > 2 { | ||||
| 			count = 2 | ||||
| 		} | ||||
| 		flag := fmt.Sprintf("%s%s", strings.Repeat("-", count), name) | ||||
| 		for _, a := range os.Args { | ||||
| 			if a == flag { | ||||
| 				return true | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) { | ||||
| 	cur := strings.TrimPrefix(lastArg, "-") | ||||
| 	cur = strings.TrimPrefix(cur, "-") | ||||
| 	for _, flag := range flags { | ||||
| 		if bflag, ok := flag.(BoolFlag); ok && bflag.Hidden { | ||||
| 			continue | ||||
| 		} | ||||
| 		for _, name := range strings.Split(flag.GetName(), ",") { | ||||
| 			name = strings.TrimSpace(name) | ||||
| 			// this will get total count utf8 letters in flag name | ||||
| 			count := utf8.RuneCountInString(name) | ||||
| 			if count > 2 { | ||||
| 				count = 2 // resuse this count to generate single - or -- in flag completion | ||||
| 			} | ||||
| 			// if flag name has more than one utf8 letter and last argument in cli has -- prefix then | ||||
| 			// skip flag completion for short flags example -v or -x | ||||
| 			if strings.HasPrefix(lastArg, "--") && count == 1 { | ||||
| 				continue | ||||
| 			} | ||||
| 			// match if last argument matches this flag and it is not repeated | ||||
| 			if strings.HasPrefix(name, cur) && cur != name && !cliArgContains(flag.GetName()) { | ||||
| 				flagCompletion := fmt.Sprintf("%s%s", strings.Repeat("-", count), name) | ||||
| 				_, _ = fmt.Fprintln(writer, flagCompletion) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func DefaultCompleteWithFlags(cmd *Command) func(c *Context) { | ||||
| 	return func(c *Context) { | ||||
| 		if len(os.Args) > 2 { | ||||
| 			lastArg := os.Args[len(os.Args)-2] | ||||
| 			if strings.HasPrefix(lastArg, "-") { | ||||
| 				printFlagSuggestions(lastArg, c.App.Flags, c.App.Writer) | ||||
| 				if cmd != nil { | ||||
| 					printFlagSuggestions(lastArg, cmd.Flags, c.App.Writer) | ||||
| 				} | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
| 		if cmd != nil { | ||||
| 			printCommandSuggestions(cmd.Subcommands, c.App.Writer) | ||||
| 		} else { | ||||
| 			printCommandSuggestions(c.App.Commands, c.App.Writer) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // ShowCommandHelpAndExit - exits with code after showing help | ||||
| func ShowCommandHelpAndExit(c *Context, command string, code int) { | ||||
| 	ShowCommandHelp(c, command) | ||||
| 	_ = ShowCommandHelp(c, command) | ||||
| 	os.Exit(code) | ||||
| } | ||||
|  | ||||
| @@ -208,7 +214,7 @@ func ShowVersion(c *Context) { | ||||
| } | ||||
|  | ||||
| func printVersion(c *Context) { | ||||
| 	fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version) | ||||
| 	_, _ = fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version) | ||||
| } | ||||
|  | ||||
| // ShowCompletions prints the lists of commands within a given context | ||||
| @@ -222,19 +228,22 @@ func ShowCompletions(c *Context) { | ||||
| // ShowCommandCompletions prints the custom completions for a given command | ||||
| func ShowCommandCompletions(ctx *Context, command string) { | ||||
| 	c := ctx.App.Command(command) | ||||
| 	if c != nil && c.BashComplete != nil { | ||||
| 		c.BashComplete(ctx) | ||||
| 	if c != nil { | ||||
| 		if c.BashComplete != nil { | ||||
| 			c.BashComplete(ctx) | ||||
| 		} else { | ||||
| 			DefaultCompleteWithFlags(c)(ctx) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| } | ||||
|  | ||||
| func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc map[string]interface{}) { | ||||
| 	funcMap := template.FuncMap{ | ||||
| 		"join": strings.Join, | ||||
| 	} | ||||
| 	if customFunc != nil { | ||||
| 		for key, value := range customFunc { | ||||
| 			funcMap[key] = value | ||||
| 		} | ||||
| 	for key, value := range customFunc { | ||||
| 		funcMap[key] = value | ||||
| 	} | ||||
|  | ||||
| 	w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0) | ||||
| @@ -244,11 +253,11 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc m | ||||
| 		// If the writer is closed, t.Execute will fail, and there's nothing | ||||
| 		// we can do to recover. | ||||
| 		if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" { | ||||
| 			fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err) | ||||
| 			_, _ = fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err) | ||||
| 		} | ||||
| 		return | ||||
| 	} | ||||
| 	w.Flush() | ||||
| 	_ = w.Flush() | ||||
| } | ||||
|  | ||||
| func printHelp(out io.Writer, templ string, data interface{}) { | ||||
| @@ -281,7 +290,7 @@ func checkHelp(c *Context) bool { | ||||
|  | ||||
| func checkCommandHelp(c *Context, name string) bool { | ||||
| 	if c.Bool("h") || c.Bool("help") { | ||||
| 		ShowCommandHelp(c, name) | ||||
| 		_ = ShowCommandHelp(c, name) | ||||
| 		return true | ||||
| 	} | ||||
|  | ||||
| @@ -290,7 +299,7 @@ func checkCommandHelp(c *Context, name string) bool { | ||||
|  | ||||
| func checkSubcommandHelp(c *Context) bool { | ||||
| 	if c.Bool("h") || c.Bool("help") { | ||||
| 		ShowSubcommandHelp(c) | ||||
| 		_ = ShowSubcommandHelp(c) | ||||
| 		return true | ||||
| 	} | ||||
|  | ||||
|   | ||||
							
								
								
									
										80
									
								
								vendor/github.com/urfave/cli/parse.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								vendor/github.com/urfave/cli/parse.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,80 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| type iterativeParser interface { | ||||
| 	newFlagSet() (*flag.FlagSet, error) | ||||
| 	useShortOptionHandling() bool | ||||
| } | ||||
|  | ||||
| // To enable short-option handling (e.g., "-it" vs "-i -t") we have to | ||||
| // iteratively catch parsing errors.  This way we achieve LR parsing without | ||||
| // transforming any arguments. Otherwise, there is no way we can discriminate | ||||
| // combined short options from common arguments that should be left untouched. | ||||
| func parseIter(ip iterativeParser, args []string) (*flag.FlagSet, error) { | ||||
| 	for { | ||||
| 		set, err := ip.newFlagSet() | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
|  | ||||
| 		err = set.Parse(args) | ||||
| 		if !ip.useShortOptionHandling() || err == nil { | ||||
| 			return set, err | ||||
| 		} | ||||
|  | ||||
| 		errStr := err.Error() | ||||
| 		trimmed := strings.TrimPrefix(errStr, "flag provided but not defined: ") | ||||
| 		if errStr == trimmed { | ||||
| 			return nil, err | ||||
| 		} | ||||
|  | ||||
| 		// regenerate the initial args with the split short opts | ||||
| 		newArgs := []string{} | ||||
| 		for i, arg := range args { | ||||
| 			if arg != trimmed { | ||||
| 				newArgs = append(newArgs, arg) | ||||
| 				continue | ||||
| 			} | ||||
|  | ||||
| 			shortOpts := splitShortOptions(set, trimmed) | ||||
| 			if len(shortOpts) == 1 { | ||||
| 				return nil, err | ||||
| 			} | ||||
|  | ||||
| 			// add each short option and all remaining arguments | ||||
| 			newArgs = append(newArgs, shortOpts...) | ||||
| 			newArgs = append(newArgs, args[i+1:]...) | ||||
| 			args = newArgs | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func splitShortOptions(set *flag.FlagSet, arg string) []string { | ||||
| 	shortFlagsExist := func(s string) bool { | ||||
| 		for _, c := range s[1:] { | ||||
| 			if f := set.Lookup(string(c)); f == nil { | ||||
| 				return false | ||||
| 			} | ||||
| 		} | ||||
| 		return true | ||||
| 	} | ||||
|  | ||||
| 	if !isSplittable(arg) || !shortFlagsExist(arg) { | ||||
| 		return []string{arg} | ||||
| 	} | ||||
|  | ||||
| 	separated := make([]string, 0, len(arg)-1) | ||||
| 	for _, flagChar := range arg[1:] { | ||||
| 		separated = append(separated, "-"+string(flagChar)) | ||||
| 	} | ||||
|  | ||||
| 	return separated | ||||
| } | ||||
|  | ||||
| func isSplittable(flagArg string) bool { | ||||
| 	return strings.HasPrefix(flagArg, "-") && !strings.HasPrefix(flagArg, "--") && len(flagArg) > 2 | ||||
| } | ||||
							
								
								
									
										29
									
								
								vendor/github.com/urfave/cli/sort.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								vendor/github.com/urfave/cli/sort.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| package cli | ||||
|  | ||||
| import "unicode" | ||||
|  | ||||
| // lexicographicLess compares strings alphabetically considering case. | ||||
| func lexicographicLess(i, j string) bool { | ||||
| 	iRunes := []rune(i) | ||||
| 	jRunes := []rune(j) | ||||
|  | ||||
| 	lenShared := len(iRunes) | ||||
| 	if lenShared > len(jRunes) { | ||||
| 		lenShared = len(jRunes) | ||||
| 	} | ||||
|  | ||||
| 	for index := 0; index < lenShared; index++ { | ||||
| 		ir := iRunes[index] | ||||
| 		jr := jRunes[index] | ||||
|  | ||||
| 		if lir, ljr := unicode.ToLower(ir), unicode.ToLower(jr); lir != ljr { | ||||
| 			return lir < ljr | ||||
| 		} | ||||
|  | ||||
| 		if ir != jr { | ||||
| 			return ir < jr | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return i < j | ||||
| } | ||||
							
								
								
									
										121
									
								
								vendor/github.com/urfave/cli/template.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								vendor/github.com/urfave/cli/template.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,121 @@ | ||||
| package cli | ||||
|  | ||||
| // AppHelpTemplate is the text template for the Default help topic. | ||||
| // cli.go uses text/template to render templates. You can | ||||
| // render custom help text by setting this variable. | ||||
| var AppHelpTemplate = `NAME: | ||||
|    {{.Name}}{{if .Usage}} - {{.Usage}}{{end}} | ||||
|  | ||||
| USAGE: | ||||
|    {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} | ||||
|  | ||||
| VERSION: | ||||
|    {{.Version}}{{end}}{{end}}{{if .Description}} | ||||
|  | ||||
| DESCRIPTION: | ||||
|    {{.Description}}{{end}}{{if len .Authors}} | ||||
|  | ||||
| AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: | ||||
|    {{range $index, $author := .Authors}}{{if $index}} | ||||
|    {{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}} | ||||
|  | ||||
| COMMANDS:{{range .VisibleCategories}}{{if .Name}} | ||||
|  | ||||
|    {{.Name}}:{{range .VisibleCommands}} | ||||
|      {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}} | ||||
|    {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} | ||||
|  | ||||
| GLOBAL OPTIONS: | ||||
|    {{range $index, $option := .VisibleFlags}}{{if $index}} | ||||
|    {{end}}{{$option}}{{end}}{{end}}{{if .Copyright}} | ||||
|  | ||||
| COPYRIGHT: | ||||
|    {{.Copyright}}{{end}} | ||||
| ` | ||||
|  | ||||
| // CommandHelpTemplate is the text template for the command help topic. | ||||
| // cli.go uses text/template to render templates. You can | ||||
| // render custom help text by setting this variable. | ||||
| var CommandHelpTemplate = `NAME: | ||||
|    {{.HelpName}} - {{.Usage}} | ||||
|  | ||||
| USAGE: | ||||
|    {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}} | ||||
|  | ||||
| CATEGORY: | ||||
|    {{.Category}}{{end}}{{if .Description}} | ||||
|  | ||||
| DESCRIPTION: | ||||
|    {{.Description}}{{end}}{{if .VisibleFlags}} | ||||
|  | ||||
| OPTIONS: | ||||
|    {{range .VisibleFlags}}{{.}} | ||||
|    {{end}}{{end}} | ||||
| ` | ||||
|  | ||||
| // SubcommandHelpTemplate is the text template for the subcommand help topic. | ||||
| // cli.go uses text/template to render templates. You can | ||||
| // render custom help text by setting this variable. | ||||
| var SubcommandHelpTemplate = `NAME: | ||||
|    {{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}} | ||||
|  | ||||
| USAGE: | ||||
|    {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} | ||||
|  | ||||
| COMMANDS:{{range .VisibleCategories}}{{if .Name}} | ||||
|  | ||||
|    {{.Name}}:{{range .VisibleCommands}} | ||||
|      {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}} | ||||
|    {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} | ||||
|  | ||||
| OPTIONS: | ||||
|    {{range .VisibleFlags}}{{.}} | ||||
|    {{end}}{{end}} | ||||
| ` | ||||
|  | ||||
| var MarkdownDocTemplate = `% {{ .App.Name }}(8) {{ .App.Description }} | ||||
|  | ||||
| % {{ .App.Author }} | ||||
|  | ||||
| # NAME | ||||
|  | ||||
| {{ .App.Name }}{{ if .App.Usage }} - {{ .App.Usage }}{{ end }} | ||||
|  | ||||
| # SYNOPSIS | ||||
|  | ||||
| {{ .App.Name }} | ||||
| {{ if .SynopsisArgs }} | ||||
| ` + "```" + ` | ||||
| {{ range $v := .SynopsisArgs }}{{ $v }}{{ end }}` + "```" + ` | ||||
| {{ end }}{{ if .App.UsageText }} | ||||
| # DESCRIPTION | ||||
|  | ||||
| {{ .App.UsageText }} | ||||
| {{ end }} | ||||
| **Usage**: | ||||
|  | ||||
| ` + "```" + ` | ||||
| {{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...] | ||||
| ` + "```" + ` | ||||
| {{ if .GlobalArgs }} | ||||
| # GLOBAL OPTIONS | ||||
| {{ range $v := .GlobalArgs }} | ||||
| {{ $v }}{{ end }} | ||||
| {{ end }}{{ if .Commands }} | ||||
| # COMMANDS | ||||
| {{ range $v := .Commands }} | ||||
| {{ $v }}{{ end }}{{ end }}` | ||||
|  | ||||
| var FishCompletionTemplate = `# {{ .App.Name }} fish shell completion | ||||
|  | ||||
| function __fish_{{ .App.Name }}_no_subcommand --description 'Test if there has been any subcommand yet' | ||||
|     for i in (commandline -opc) | ||||
|         if contains -- $i{{ range $v := .AllCommands }} {{ $v }}{{ end }} | ||||
|             return 1 | ||||
|         end | ||||
|     end | ||||
|     return 0 | ||||
| end | ||||
|  | ||||
| {{ range $v := .Completions }}{{ $v }} | ||||
| {{ end }}` | ||||
		Reference in New Issue
	
	Block a user
	 Michael Crosby
					Michael Crosby