mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-31 09:15:26 +01:00 
			
		
		
		
	chore(cli): upgrade urfave/cli to v2 version (#85)
chore(cli): upgrade urfave/cli to v2 version Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
		 appleboy
					appleboy
				
			
				
					committed by
					
						 Andrew Thornton
						Andrew Thornton
					
				
			
			
				
	
			
			
			 Andrew Thornton
						Andrew Thornton
					
				
			
						parent
						
							0a5cdd60ac
						
					
				
				
					commit
					c20d7d45aa
				
			
							
								
								
									
										2
									
								
								vendor/github.com/urfave/cli/v2/.flake8
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/urfave/cli/v2/.flake8
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| [flake8] | ||||
| max-line-length = 120 | ||||
							
								
								
									
										5
									
								
								vendor/github.com/urfave/cli/v2/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								vendor/github.com/urfave/cli/v2/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| *.coverprofile | ||||
| *.orig | ||||
| node_modules/ | ||||
| vendor | ||||
| .idea | ||||
							
								
								
									
										74
									
								
								vendor/github.com/urfave/cli/v2/CODE_OF_CONDUCT.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								vendor/github.com/urfave/cli/v2/CODE_OF_CONDUCT.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | ||||
| # Contributor Covenant Code of Conduct | ||||
|  | ||||
| ## Our Pledge | ||||
|  | ||||
| In the interest of fostering an open and welcoming environment, we as | ||||
| contributors and maintainers pledge to making participation in our project and | ||||
| our community a harassment-free experience for everyone, regardless of age, body | ||||
| size, disability, ethnicity, gender identity and expression, level of experience, | ||||
| education, socio-economic status, nationality, personal appearance, race, | ||||
| religion, or sexual identity and orientation. | ||||
|  | ||||
| ## Our Standards | ||||
|  | ||||
| Examples of behavior that contributes to creating a positive environment | ||||
| include: | ||||
|  | ||||
| * Using welcoming and inclusive language | ||||
| * Being respectful of differing viewpoints and experiences | ||||
| * Gracefully accepting constructive criticism | ||||
| * Focusing on what is best for the community | ||||
| * Showing empathy towards other community members | ||||
|  | ||||
| Examples of unacceptable behavior by participants include: | ||||
|  | ||||
| * The use of sexualized language or imagery and unwelcome sexual attention or | ||||
|   advances | ||||
| * Trolling, insulting/derogatory comments, and personal or political attacks | ||||
| * Public or private harassment | ||||
| * Publishing others' private information, such as a physical or electronic | ||||
|   address, without explicit permission | ||||
| * Other conduct which could reasonably be considered inappropriate in a | ||||
|   professional setting | ||||
|  | ||||
| ## Our Responsibilities | ||||
|  | ||||
| Project maintainers are responsible for clarifying the standards of acceptable | ||||
| behavior and are expected to take appropriate and fair corrective action in | ||||
| response to any instances of unacceptable behavior. | ||||
|  | ||||
| Project maintainers have the right and responsibility to remove, edit, or | ||||
| reject comments, commits, code, wiki edits, issues, and other contributions | ||||
| that are not aligned to this Code of Conduct, or to ban temporarily or | ||||
| permanently any contributor for other behaviors that they deem inappropriate, | ||||
| threatening, offensive, or harmful. | ||||
|  | ||||
| ## Scope | ||||
|  | ||||
| This Code of Conduct applies both within project spaces and in public spaces | ||||
| when an individual is representing the project or its community. Examples of | ||||
| representing a project or community include using an official project e-mail | ||||
| address, posting via an official social media account, or acting as an appointed | ||||
| representative at an online or offline event. Representation of a project may be | ||||
| further defined and clarified by project maintainers. | ||||
|  | ||||
| ## Enforcement | ||||
|  | ||||
| Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||||
| reported by contacting Dan Buch at dan@meatballhat.com. All complaints will be | ||||
| reviewed and investigated and will result in a response that is deemed necessary | ||||
| and appropriate to the circumstances. The project team is obligated to maintain | ||||
| confidentiality with regard to the reporter of an incident.  Further details of | ||||
| specific enforcement policies may be posted separately. | ||||
|  | ||||
| Project maintainers who do not follow or enforce the Code of Conduct in good | ||||
| faith may face temporary or permanent repercussions as determined by other | ||||
| members of the project's leadership. | ||||
|  | ||||
| ## Attribution | ||||
|  | ||||
| This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||||
| available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||||
|  | ||||
| [homepage]: https://www.contributor-covenant.org | ||||
|  | ||||
							
								
								
									
										21
									
								
								vendor/github.com/urfave/cli/v2/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								vendor/github.com/urfave/cli/v2/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| MIT License | ||||
|  | ||||
| Copyright (c) 2016 Jeremy Saenz & Contributors | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all | ||||
| copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
| SOFTWARE. | ||||
							
								
								
									
										68
									
								
								vendor/github.com/urfave/cli/v2/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								vendor/github.com/urfave/cli/v2/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| 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) | ||||
| [](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 | ||||
| applications in an expressive way. | ||||
|  | ||||
| ## Usage Documentation | ||||
|  | ||||
| Usage documentation exists for each major version. Don't know what version you're on? You're probably using the version from the `master` branch, which is currently `v2`. | ||||
|  | ||||
| - `v2` - [./docs/v2/manual.md](./docs/v2/manual.md) | ||||
| - `v1` - [./docs/v1/manual.md](./docs/v1/manual.md) | ||||
|  | ||||
| ## Installation | ||||
|  | ||||
| Make sure you have a working Go environment.  Go version 1.11+ is supported. [See the install instructions for Go](http://golang.org/doc/install.html). | ||||
|  | ||||
| Go Modules are strongly recommended when using this package. [See the go blog guide on using Go Modules](https://blog.golang.org/using-go-modules). | ||||
|  | ||||
| ### Using `v2` releases | ||||
|  | ||||
| ``` | ||||
| $ GO111MODULE=on go get github.com/urfave/cli/v2 | ||||
| ``` | ||||
|  | ||||
| ```go | ||||
| ... | ||||
| import ( | ||||
|   "github.com/urfave/cli/v2" // imports as package "cli" | ||||
| ) | ||||
| ... | ||||
| ``` | ||||
|  | ||||
| ### Using `v1` releases | ||||
|  | ||||
| ``` | ||||
| $ GO111MODULE=on go get github.com/urfave/cli | ||||
| ``` | ||||
|  | ||||
| ```go | ||||
| ... | ||||
| import ( | ||||
|   "github.com/urfave/cli" | ||||
| ) | ||||
| ... | ||||
| ``` | ||||
|  | ||||
| ### GOPATH | ||||
|  | ||||
| Make sure your `PATH` includes the `$GOPATH/bin` directory so your commands can | ||||
| be easily used: | ||||
| ``` | ||||
| export PATH=$PATH:$GOPATH/bin | ||||
| ``` | ||||
|  | ||||
| ### Supported platforms | ||||
|  | ||||
| cli is tested against multiple versions of Go on Linux, and against the latest | ||||
| released version of Go on OS X and Windows. This project uses Github Actions for | ||||
| builds. For more build info, please look at the [./.github/workflows/cli.yml](https://github.com/urfave/cli/blob/master/.github/workflows/cli.yml). | ||||
							
								
								
									
										558
									
								
								vendor/github.com/urfave/cli/v2/app.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										558
									
								
								vendor/github.com/urfave/cli/v2/app.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,558 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"reflect" | ||||
| 	"sort" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	changeLogURL            = "https://github.com/urfave/cli/blob/master/docs/CHANGELOG.md" | ||||
| 	appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) | ||||
| 	contactSysadmin         = "This is an error in the application.  Please contact the distributor of this application if this is not you." | ||||
| 	errInvalidActionType    = NewExitError("ERROR invalid Action type. "+ | ||||
| 		fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error).  %s", contactSysadmin)+ | ||||
| 		fmt.Sprintf("See %s", appActionDeprecationURL), 2) | ||||
| ) | ||||
|  | ||||
| // App is the main structure of a cli application. It is recommended that | ||||
| // an app be created with the cli.NewApp() function | ||||
| type App struct { | ||||
| 	// The name of the program. Defaults to path.Base(os.Args[0]) | ||||
| 	Name string | ||||
| 	// Full name of command for help, defaults to Name | ||||
| 	HelpName string | ||||
| 	// Description of the program. | ||||
| 	Usage string | ||||
| 	// Text to override the USAGE section of help | ||||
| 	UsageText string | ||||
| 	// Description of the program argument format. | ||||
| 	ArgsUsage string | ||||
| 	// Version of the program | ||||
| 	Version string | ||||
| 	// Description of the program | ||||
| 	Description string | ||||
| 	// List of commands to execute | ||||
| 	Commands []*Command | ||||
| 	// List of flags to parse | ||||
| 	Flags []Flag | ||||
| 	// Boolean to enable bash completion commands | ||||
| 	EnableBashCompletion bool | ||||
| 	// Boolean to hide built-in help command | ||||
| 	HideHelp bool | ||||
| 	// Boolean to hide built-in version flag and the VERSION section of help | ||||
| 	HideVersion bool | ||||
| 	// categories contains the categorized commands and is populated on app startup | ||||
| 	categories CommandCategories | ||||
| 	// An action to execute when the shell completion flag is set | ||||
| 	BashComplete BashCompleteFunc | ||||
| 	// An action to execute before any subcommands are run, but after the context is ready | ||||
| 	// If a non-nil error is returned, no subcommands are run | ||||
| 	Before BeforeFunc | ||||
| 	// An action to execute after any subcommands are run, but after the subcommand has finished | ||||
| 	// It is run even if Action() panics | ||||
| 	After AfterFunc | ||||
| 	// The action to execute when no subcommands are specified | ||||
| 	Action ActionFunc | ||||
| 	// Execute this function if the proper command cannot be found | ||||
| 	CommandNotFound CommandNotFoundFunc | ||||
| 	// Execute this function if an usage error occurs | ||||
| 	OnUsageError OnUsageErrorFunc | ||||
| 	// Compilation date | ||||
| 	Compiled time.Time | ||||
| 	// List of all authors who contributed | ||||
| 	Authors []*Author | ||||
| 	// Copyright of the binary if any | ||||
| 	Copyright string | ||||
| 	// Writer writer to write output to | ||||
| 	Writer io.Writer | ||||
| 	// ErrWriter writes error output | ||||
| 	ErrWriter io.Writer | ||||
| 	// Execute this function to handle ExitErrors. If not provided, HandleExitCoder is provided to | ||||
| 	// function as a default, so this is optional. | ||||
| 	ExitErrHandler ExitErrHandlerFunc | ||||
| 	// Other custom info | ||||
| 	Metadata map[string]interface{} | ||||
| 	// Carries a function which returns app specific info. | ||||
| 	ExtraInfo func() map[string]string | ||||
| 	// CustomAppHelpTemplate the text template for app help topic. | ||||
| 	// 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 arguments into one | ||||
| 	// i.e. foobar -o -v -> foobar -ov | ||||
| 	UseShortOptionHandling bool | ||||
|  | ||||
| 	didSetup bool | ||||
| } | ||||
|  | ||||
| // Tries to find out when this binary was compiled. | ||||
| // Returns the current time if it fails to find it. | ||||
| func compileTime() time.Time { | ||||
| 	info, err := os.Stat(os.Args[0]) | ||||
| 	if err != nil { | ||||
| 		return time.Now() | ||||
| 	} | ||||
| 	return info.ModTime() | ||||
| } | ||||
|  | ||||
| // NewApp creates a new cli Application with some reasonable defaults for Name, | ||||
| // Usage, Version and Action. | ||||
| func NewApp() *App { | ||||
| 	return &App{ | ||||
| 		Name:         filepath.Base(os.Args[0]), | ||||
| 		HelpName:     filepath.Base(os.Args[0]), | ||||
| 		Usage:        "A new cli application", | ||||
| 		UsageText:    "", | ||||
| 		BashComplete: DefaultAppComplete, | ||||
| 		Action:       helpCommand.Action, | ||||
| 		Compiled:     compileTime(), | ||||
| 		Writer:       os.Stdout, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Setup runs initialization code to ensure all data structures are ready for | ||||
| // `Run` or inspection prior to `Run`.  It is internally called by `Run`, but | ||||
| // will return early if setup has already happened. | ||||
| func (a *App) Setup() { | ||||
| 	if a.didSetup { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	a.didSetup = true | ||||
|  | ||||
| 	if a.Name == "" { | ||||
| 		a.Name = filepath.Base(os.Args[0]) | ||||
| 	} | ||||
|  | ||||
| 	if a.HelpName == "" { | ||||
| 		a.HelpName = filepath.Base(os.Args[0]) | ||||
| 	} | ||||
|  | ||||
| 	if a.Usage == "" { | ||||
| 		a.Usage = "A new cli application" | ||||
| 	} | ||||
|  | ||||
| 	if a.Version == "" { | ||||
| 		a.HideVersion = true | ||||
| 	} | ||||
|  | ||||
| 	if a.BashComplete == nil { | ||||
| 		a.BashComplete = DefaultAppComplete | ||||
| 	} | ||||
|  | ||||
| 	if a.Action == nil { | ||||
| 		a.Action = helpCommand.Action | ||||
| 	} | ||||
|  | ||||
| 	if a.Compiled == (time.Time{}) { | ||||
| 		a.Compiled = compileTime() | ||||
| 	} | ||||
|  | ||||
| 	if a.Writer == nil { | ||||
| 		a.Writer = os.Stdout | ||||
| 	} | ||||
|  | ||||
| 	var newCommands []*Command | ||||
|  | ||||
| 	for _, c := range a.Commands { | ||||
| 		if c.HelpName == "" { | ||||
| 			c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) | ||||
| 		} | ||||
| 		newCommands = append(newCommands, c) | ||||
| 	} | ||||
| 	a.Commands = newCommands | ||||
|  | ||||
| 	if a.Command(helpCommand.Name) == nil && !a.HideHelp { | ||||
| 		a.appendCommand(helpCommand) | ||||
|  | ||||
| 		if HelpFlag != nil { | ||||
| 			a.appendFlag(HelpFlag) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if !a.HideVersion { | ||||
| 		a.appendFlag(VersionFlag) | ||||
| 	} | ||||
|  | ||||
| 	a.categories = newCommandCategories() | ||||
| 	for _, command := range a.Commands { | ||||
| 		a.categories.AddCommand(command.Category, command) | ||||
| 	} | ||||
| 	sort.Sort(a.categories.(*commandCategories)) | ||||
|  | ||||
| 	if a.Metadata == nil { | ||||
| 		a.Metadata = make(map[string]interface{}) | ||||
| 	} | ||||
|  | ||||
| 	if a.Writer == nil { | ||||
| 		a.Writer = os.Stdout | ||||
| 	} | ||||
| } | ||||
|  | ||||
| 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) { | ||||
| 	return a.RunContext(context.Background(), arguments) | ||||
| } | ||||
|  | ||||
| // RunContext is like Run except it takes a Context that will be | ||||
| // passed to its commands and sub-commands. Through this, you can | ||||
| // propagate timeouts and cancellation requests | ||||
| func (a *App) RunContext(ctx context.Context, arguments []string) (err error) { | ||||
| 	a.Setup() | ||||
|  | ||||
| 	// handle the completion flag separately from the flagset since | ||||
| 	// completion could be attempted after a flag, but before its value was put | ||||
| 	// on the command line. this causes the flagset to interpret the completion | ||||
| 	// flag name as the value of the flag before it which is undesirable | ||||
| 	// note that we can only do this because the shell autocomplete function | ||||
| 	// always appends the completion flag at the end of the command | ||||
| 	shellComplete, arguments := checkShellCompleteFlag(a, arguments) | ||||
|  | ||||
| 	set, err := a.newFlagSet() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	err = parseIter(set, a, arguments[1:], shellComplete) | ||||
| 	nerr := normalizeFlags(a.Flags, set) | ||||
| 	context := NewContext(a, set, &Context{Context: ctx}) | ||||
| 	if nerr != nil { | ||||
| 		_, _ = fmt.Fprintln(a.Writer, nerr) | ||||
| 		_ = ShowAppHelp(context) | ||||
| 		return nerr | ||||
| 	} | ||||
| 	context.shellComplete = shellComplete | ||||
|  | ||||
| 	if checkCompletions(context) { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	if err != nil { | ||||
| 		if a.OnUsageError != nil { | ||||
| 			err := a.OnUsageError(context, err, false) | ||||
| 			a.handleExitCoder(context, err) | ||||
| 			return err | ||||
| 		} | ||||
| 		_, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) | ||||
| 		_ = ShowAppHelp(context) | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if !a.HideHelp && checkHelp(context) { | ||||
| 		_ = ShowAppHelp(context) | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	if !a.HideVersion && checkVersion(context) { | ||||
| 		ShowVersion(context) | ||||
| 		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 { | ||||
| 				if err != nil { | ||||
| 					err = newMultiError(err, afterErr) | ||||
| 				} else { | ||||
| 					err = afterErr | ||||
| 				} | ||||
| 			} | ||||
| 		}() | ||||
| 	} | ||||
|  | ||||
| 	if a.Before != nil { | ||||
| 		beforeErr := a.Before(context) | ||||
| 		if beforeErr != nil { | ||||
| 			_, _ = fmt.Fprintf(a.Writer, "%v\n\n", beforeErr) | ||||
| 			_ = ShowAppHelp(context) | ||||
| 			a.handleExitCoder(context, beforeErr) | ||||
| 			err = beforeErr | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	args := context.Args() | ||||
| 	if args.Present() { | ||||
| 		name := args.First() | ||||
| 		c := a.Command(name) | ||||
| 		if c != nil { | ||||
| 			return c.Run(context) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if a.Action == nil { | ||||
| 		a.Action = helpCommand.Action | ||||
| 	} | ||||
|  | ||||
| 	// Run default Action | ||||
| 	err = a.Action(context) | ||||
|  | ||||
| 	a.handleExitCoder(context, err) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| // RunAndExitOnError calls .Run() and exits non-zero if an error was returned | ||||
| // | ||||
| // Deprecated: instead you should return an error that fulfills cli.ExitCoder | ||||
| // to cli.App.Run. This will cause the application to exit with the given eror | ||||
| // code in the cli.ExitCoder | ||||
| func (a *App) RunAndExitOnError() { | ||||
| 	if err := a.Run(os.Args); err != nil { | ||||
| 		_, _ = fmt.Fprintln(a.errWriter(), err) | ||||
| 		OsExiter(1) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // RunAsSubcommand invokes the subcommand given the context, parses ctx.Args() to | ||||
| // generate command-specific flags | ||||
| func (a *App) RunAsSubcommand(ctx *Context) (err error) { | ||||
| 	a.Setup() | ||||
|  | ||||
| 	// append help to commands | ||||
| 	if len(a.Commands) > 0 { | ||||
| 		if a.Command(helpCommand.Name) == nil && !a.HideHelp { | ||||
| 			a.appendCommand(helpCommand) | ||||
|  | ||||
| 			if HelpFlag != nil { | ||||
| 				a.appendFlag(HelpFlag) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	var newCmds []*Command | ||||
| 	for _, c := range a.Commands { | ||||
| 		if c.HelpName == "" { | ||||
| 			c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) | ||||
| 		} | ||||
| 		newCmds = append(newCmds, c) | ||||
| 	} | ||||
| 	a.Commands = newCmds | ||||
|  | ||||
| 	set, err := a.newFlagSet() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	err = parseIter(set, a, ctx.Args().Tail(), ctx.shellComplete) | ||||
| 	nerr := normalizeFlags(a.Flags, set) | ||||
| 	context := NewContext(a, set, ctx) | ||||
|  | ||||
| 	if nerr != nil { | ||||
| 		_, _ = fmt.Fprintln(a.Writer, nerr) | ||||
| 		_, _ = fmt.Fprintln(a.Writer) | ||||
| 		if len(a.Commands) > 0 { | ||||
| 			_ = ShowSubcommandHelp(context) | ||||
| 		} else { | ||||
| 			_ = ShowCommandHelp(ctx, context.Args().First()) | ||||
| 		} | ||||
| 		return nerr | ||||
| 	} | ||||
|  | ||||
| 	if checkCompletions(context) { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	if err != nil { | ||||
| 		if a.OnUsageError != nil { | ||||
| 			err = a.OnUsageError(context, err, true) | ||||
| 			a.handleExitCoder(context, err) | ||||
| 			return err | ||||
| 		} | ||||
| 		_, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error()) | ||||
| 		_ = ShowSubcommandHelp(context) | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if len(a.Commands) > 0 { | ||||
| 		if checkSubcommandHelp(context) { | ||||
| 			return nil | ||||
| 		} | ||||
| 	} else { | ||||
| 		if checkCommandHelp(ctx, context.Args().First()) { | ||||
| 			return nil | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	cerr := checkRequiredFlags(a.Flags, context) | ||||
| 	if cerr != nil { | ||||
| 		_ = ShowSubcommandHelp(context) | ||||
| 		return cerr | ||||
| 	} | ||||
|  | ||||
| 	if a.After != nil { | ||||
| 		defer func() { | ||||
| 			afterErr := a.After(context) | ||||
| 			if afterErr != nil { | ||||
| 				a.handleExitCoder(context, err) | ||||
| 				if err != nil { | ||||
| 					err = newMultiError(err, afterErr) | ||||
| 				} else { | ||||
| 					err = afterErr | ||||
| 				} | ||||
| 			} | ||||
| 		}() | ||||
| 	} | ||||
|  | ||||
| 	if a.Before != nil { | ||||
| 		beforeErr := a.Before(context) | ||||
| 		if beforeErr != nil { | ||||
| 			a.handleExitCoder(context, beforeErr) | ||||
| 			err = beforeErr | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	args := context.Args() | ||||
| 	if args.Present() { | ||||
| 		name := args.First() | ||||
| 		c := a.Command(name) | ||||
| 		if c != nil { | ||||
| 			return c.Run(context) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// Run default Action | ||||
| 	err = a.Action(context) | ||||
|  | ||||
| 	a.handleExitCoder(context, err) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| // Command returns the named command on App. Returns nil if the command does not exist | ||||
| func (a *App) Command(name string) *Command { | ||||
| 	for _, c := range a.Commands { | ||||
| 		if c.HasName(name) { | ||||
| 			return c | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // VisibleCategories returns a slice of categories and commands that are | ||||
| // Hidden=false | ||||
| func (a *App) VisibleCategories() []CommandCategory { | ||||
| 	ret := []CommandCategory{} | ||||
| 	for _, category := range a.categories.Categories() { | ||||
| 		if visible := func() CommandCategory { | ||||
| 			if len(category.VisibleCommands()) > 0 { | ||||
| 				return category | ||||
| 			} | ||||
| 			return nil | ||||
| 		}(); visible != nil { | ||||
| 			ret = append(ret, visible) | ||||
| 		} | ||||
| 	} | ||||
| 	return ret | ||||
| } | ||||
|  | ||||
| // VisibleCommands returns a slice of the Commands with Hidden=false | ||||
| func (a *App) VisibleCommands() []*Command { | ||||
| 	var ret []*Command | ||||
| 	for _, command := range a.Commands { | ||||
| 		if !command.Hidden { | ||||
| 			ret = append(ret, command) | ||||
| 		} | ||||
| 	} | ||||
| 	return ret | ||||
| } | ||||
|  | ||||
| // VisibleFlags returns a slice of the Flags with Hidden=false | ||||
| func (a *App) VisibleFlags() []Flag { | ||||
| 	return visibleFlags(a.Flags) | ||||
| } | ||||
|  | ||||
| func (a *App) hasFlag(flag Flag) bool { | ||||
| 	for _, f := range a.Flags { | ||||
| 		if reflect.DeepEqual(flag, f) { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| func (a *App) errWriter() io.Writer { | ||||
| 	// When the app ErrWriter is nil use the package level one. | ||||
| 	if a.ErrWriter == nil { | ||||
| 		return ErrWriter | ||||
| 	} | ||||
|  | ||||
| 	return a.ErrWriter | ||||
| } | ||||
|  | ||||
| func (a *App) appendFlag(fl Flag) { | ||||
| 	if !hasFlag(a.Flags, fl) { | ||||
| 		a.Flags = append(a.Flags, fl) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (a *App) appendCommand(c *Command) { | ||||
| 	if !hasCommand(a.Commands, c) { | ||||
| 		a.Commands = append(a.Commands, c) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (a *App) handleExitCoder(context *Context, err error) { | ||||
| 	if a.ExitErrHandler != nil { | ||||
| 		a.ExitErrHandler(context, err) | ||||
| 	} else { | ||||
| 		HandleExitCoder(err) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Author represents someone who has contributed to a cli project. | ||||
| type Author struct { | ||||
| 	Name  string // The Authors name | ||||
| 	Email string // The Authors email | ||||
| } | ||||
|  | ||||
| // String makes Author comply to the Stringer interface, to allow an easy print in the templating process | ||||
| func (a *Author) String() string { | ||||
| 	e := "" | ||||
| 	if a.Email != "" { | ||||
| 		e = " <" + a.Email + ">" | ||||
| 	} | ||||
|  | ||||
| 	return fmt.Sprintf("%v%v", a.Name, e) | ||||
| } | ||||
|  | ||||
| // HandleAction attempts to figure out which Action signature was used.  If | ||||
| // 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) { | ||||
| 	switch a := action.(type) { | ||||
| 	case ActionFunc: | ||||
| 		return a(context) | ||||
| 	case func(*Context) error: | ||||
| 		return a(context) | ||||
| 	case func(*Context): // deprecated function signature | ||||
| 		a(context) | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	return errInvalidActionType | ||||
| } | ||||
							
								
								
									
										28
									
								
								vendor/github.com/urfave/cli/v2/appveyor.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								vendor/github.com/urfave/cli/v2/appveyor.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| version: "{build}" | ||||
|  | ||||
| os: Windows Server 2016 | ||||
|  | ||||
| image: Visual Studio 2017 | ||||
|  | ||||
| clone_folder: c:\gopath\src\github.com\urfave\cli | ||||
|  | ||||
| cache: | ||||
|   - node_modules | ||||
|  | ||||
| environment: | ||||
|   GOPATH: C:\gopath | ||||
|   GOVERSION: 1.11.x | ||||
|   GO111MODULE: on | ||||
|   GOPROXY: https://proxy.golang.org | ||||
|  | ||||
| install: | ||||
|   - set PATH=%GOPATH%\bin;C:\go\bin;%PATH% | ||||
|   - go version | ||||
|   - go env | ||||
|   - go get github.com/urfave/gfmrun/cmd/gfmrun | ||||
|   - go mod tidy | ||||
|  | ||||
| build_script: | ||||
|   - go run build.go vet | ||||
|   - go run build.go test | ||||
|   - go run build.go gfmrun docs/v1/manual.md | ||||
							
								
								
									
										54
									
								
								vendor/github.com/urfave/cli/v2/args.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								vendor/github.com/urfave/cli/v2/args.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| package cli | ||||
|  | ||||
| type Args interface { | ||||
| 	// Get returns the nth argument, or else a blank string | ||||
| 	Get(n int) string | ||||
| 	// First returns the first argument, or else a blank string | ||||
| 	First() string | ||||
| 	// Tail returns the rest of the arguments (not the first one) | ||||
| 	// or else an empty string slice | ||||
| 	Tail() []string | ||||
| 	// Len returns the length of the wrapped slice | ||||
| 	Len() int | ||||
| 	// Present checks if there are any arguments present | ||||
| 	Present() bool | ||||
| 	// Slice returns a copy of the internal slice | ||||
| 	Slice() []string | ||||
| } | ||||
|  | ||||
| type args []string | ||||
|  | ||||
| func (a *args) Get(n int) string { | ||||
| 	if len(*a) > n { | ||||
| 		return (*a)[n] | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| func (a *args) First() string { | ||||
| 	return a.Get(0) | ||||
| } | ||||
|  | ||||
| func (a *args) Tail() []string { | ||||
| 	if a.Len() >= 2 { | ||||
| 		tail := []string((*a)[1:]) | ||||
| 		ret := make([]string, len(tail)) | ||||
| 		copy(ret, tail) | ||||
| 		return ret | ||||
| 	} | ||||
| 	return []string{} | ||||
| } | ||||
|  | ||||
| func (a *args) Len() int { | ||||
| 	return len(*a) | ||||
| } | ||||
|  | ||||
| func (a *args) Present() bool { | ||||
| 	return a.Len() != 0 | ||||
| } | ||||
|  | ||||
| func (a *args) Slice() []string { | ||||
| 	ret := make([]string, len(*a)) | ||||
| 	copy(ret, *a) | ||||
| 	return ret | ||||
| } | ||||
							
								
								
									
										79
									
								
								vendor/github.com/urfave/cli/v2/category.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								vendor/github.com/urfave/cli/v2/category.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| package cli | ||||
|  | ||||
| // CommandCategories interface allows for category manipulation | ||||
| type CommandCategories interface { | ||||
| 	// AddCommand adds a command to a category, creating a new category if necessary. | ||||
| 	AddCommand(category string, command *Command) | ||||
| 	// categories returns a copy of the category slice | ||||
| 	Categories() []CommandCategory | ||||
| } | ||||
|  | ||||
| type commandCategories []*commandCategory | ||||
|  | ||||
| func newCommandCategories() CommandCategories { | ||||
| 	ret := commandCategories([]*commandCategory{}) | ||||
| 	return &ret | ||||
| } | ||||
|  | ||||
| func (c *commandCategories) Less(i, j int) bool { | ||||
| 	return lexicographicLess((*c)[i].Name(), (*c)[j].Name()) | ||||
| } | ||||
|  | ||||
| func (c *commandCategories) Len() int { | ||||
| 	return len(*c) | ||||
| } | ||||
|  | ||||
| func (c *commandCategories) Swap(i, j int) { | ||||
| 	(*c)[i], (*c)[j] = (*c)[j], (*c)[i] | ||||
| } | ||||
|  | ||||
| func (c *commandCategories) AddCommand(category string, command *Command) { | ||||
| 	for _, commandCategory := range []*commandCategory(*c) { | ||||
| 		if commandCategory.name == category { | ||||
| 			commandCategory.commands = append(commandCategory.commands, command) | ||||
| 			return | ||||
| 		} | ||||
| 	} | ||||
| 	newVal := append(*c, | ||||
| 		&commandCategory{name: category, commands: []*Command{command}}) | ||||
| 	*c = newVal | ||||
| } | ||||
|  | ||||
| func (c *commandCategories) Categories() []CommandCategory { | ||||
| 	ret := make([]CommandCategory, len(*c)) | ||||
| 	for i, cat := range *c { | ||||
| 		ret[i] = cat | ||||
| 	} | ||||
| 	return ret | ||||
| } | ||||
|  | ||||
| // CommandCategory is a category containing commands. | ||||
| type CommandCategory interface { | ||||
| 	// Name returns the category name string | ||||
| 	Name() string | ||||
| 	// VisibleCommands returns a slice of the Commands with Hidden=false | ||||
| 	VisibleCommands() []*Command | ||||
| } | ||||
|  | ||||
| type commandCategory struct { | ||||
| 	name     string | ||||
| 	commands []*Command | ||||
| } | ||||
|  | ||||
| func (c *commandCategory) Name() string { | ||||
| 	return c.name | ||||
| } | ||||
|  | ||||
| func (c *commandCategory) VisibleCommands() []*Command { | ||||
| 	if c.commands == nil { | ||||
| 		c.commands = []*Command{} | ||||
| 	} | ||||
|  | ||||
| 	var ret []*Command | ||||
| 	for _, command := range c.commands { | ||||
| 		if !command.Hidden { | ||||
| 			ret = append(ret, command) | ||||
| 		} | ||||
| 	} | ||||
| 	return ret | ||||
| } | ||||
							
								
								
									
										23
									
								
								vendor/github.com/urfave/cli/v2/cli.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								vendor/github.com/urfave/cli/v2/cli.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| // Package cli provides a minimal framework for creating and organizing command line | ||||
| // Go applications. cli is designed to be easy to understand and write, the most simple | ||||
| // cli application can be written as follows: | ||||
| //   func main() { | ||||
| //     (&cli.App{}).Run(os.Args) | ||||
| //   } | ||||
| // | ||||
| // Of course this application does not do much, so let's make this an actual application: | ||||
| //   func main() { | ||||
| //     app := &cli.App{ | ||||
| //			 Name: "greet", | ||||
| //			 Usage: "say a greeting", | ||||
| //			 Action: func(c *cli.Context) error { | ||||
| //				 fmt.Println("Greetings") | ||||
| //				 return nil | ||||
| //			 }, | ||||
| //		 } | ||||
| // | ||||
| //     app.Run(os.Args) | ||||
| //   } | ||||
| package cli | ||||
|  | ||||
| //go:generate go run flag-gen/main.go flag-gen/assets_vfsdata.go | ||||
							
								
								
									
										297
									
								
								vendor/github.com/urfave/cli/v2/command.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										297
									
								
								vendor/github.com/urfave/cli/v2/command.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,297 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // Command is a subcommand for a cli.App. | ||||
| type Command struct { | ||||
| 	// The name of the command | ||||
| 	Name string | ||||
| 	// A list of aliases for the command | ||||
| 	Aliases []string | ||||
| 	// A short description of the usage of this command | ||||
| 	Usage string | ||||
| 	// Custom text to show on USAGE section of help | ||||
| 	UsageText string | ||||
| 	// A longer explanation of how the command works | ||||
| 	Description string | ||||
| 	// A short description of the arguments of this command | ||||
| 	ArgsUsage string | ||||
| 	// The category the command is part of | ||||
| 	Category string | ||||
| 	// The function to call when checking for bash command completions | ||||
| 	BashComplete BashCompleteFunc | ||||
| 	// An action to execute before any sub-subcommands are run, but after the context is ready | ||||
| 	// If a non-nil error is returned, no sub-subcommands are run | ||||
| 	Before BeforeFunc | ||||
| 	// An action to execute after any subcommands are run, but after the subcommand has finished | ||||
| 	// It is run even if Action() panics | ||||
| 	After AfterFunc | ||||
| 	// The function to call when this command is invoked | ||||
| 	Action ActionFunc | ||||
| 	// Execute this function if a usage error occurs. | ||||
| 	OnUsageError OnUsageErrorFunc | ||||
| 	// List of child commands | ||||
| 	Subcommands []*Command | ||||
| 	// List of flags to parse | ||||
| 	Flags []Flag | ||||
| 	// Treat all flags as normal arguments if true | ||||
| 	SkipFlagParsing bool | ||||
| 	// Boolean to hide built-in help command | ||||
| 	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 | ||||
| 	commandNamePath []string | ||||
|  | ||||
| 	// CustomHelpTemplate 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. | ||||
| 	CustomHelpTemplate string | ||||
| } | ||||
|  | ||||
| type Commands []*Command | ||||
|  | ||||
| type CommandsByName []*Command | ||||
|  | ||||
| func (c CommandsByName) Len() int { | ||||
| 	return len(c) | ||||
| } | ||||
|  | ||||
| func (c CommandsByName) Less(i, j int) bool { | ||||
| 	return lexicographicLess(c[i].Name, c[j].Name) | ||||
| } | ||||
|  | ||||
| func (c CommandsByName) Swap(i, j int) { | ||||
| 	c[i], c[j] = c[j], c[i] | ||||
| } | ||||
|  | ||||
| // FullName returns the full name of the command. | ||||
| // For subcommands this ensures that parent commands are part of the command path | ||||
| func (c *Command) FullName() string { | ||||
| 	if c.commandNamePath == nil { | ||||
| 		return c.Name | ||||
| 	} | ||||
| 	return strings.Join(c.commandNamePath, " ") | ||||
| } | ||||
|  | ||||
| // Run invokes the command given the context, parses ctx.Args() to generate command-specific flags | ||||
| func (c *Command) Run(ctx *Context) (err error) { | ||||
| 	if len(c.Subcommands) > 0 { | ||||
| 		return c.startApp(ctx) | ||||
| 	} | ||||
|  | ||||
| 	if !c.HideHelp && HelpFlag != nil { | ||||
| 		// append help to flags | ||||
| 		c.appendFlag(HelpFlag) | ||||
| 	} | ||||
|  | ||||
| 	if ctx.App.UseShortOptionHandling { | ||||
| 		c.UseShortOptionHandling = true | ||||
| 	} | ||||
|  | ||||
| 	set, err := c.parseFlags(ctx.Args(), ctx.shellComplete) | ||||
|  | ||||
| 	context := NewContext(ctx.App, set, ctx) | ||||
| 	context.Command = c | ||||
| 	if checkCommandCompletions(context, c.Name) { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	if err != nil { | ||||
| 		if c.OnUsageError != nil { | ||||
| 			err = c.OnUsageError(context, err, false) | ||||
| 			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) | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if checkCommandHelp(context, c.Name) { | ||||
| 		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) | ||||
| 			if afterErr != nil { | ||||
| 				context.App.handleExitCoder(context, err) | ||||
| 				if err != nil { | ||||
| 					err = newMultiError(err, afterErr) | ||||
| 				} else { | ||||
| 					err = afterErr | ||||
| 				} | ||||
| 			} | ||||
| 		}() | ||||
| 	} | ||||
|  | ||||
| 	if c.Before != nil { | ||||
| 		err = c.Before(context) | ||||
| 		if err != nil { | ||||
| 			_ = ShowCommandHelp(context, c.Name) | ||||
| 			context.App.handleExitCoder(context, err) | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if c.Action == nil { | ||||
| 		c.Action = helpSubcommand.Action | ||||
| 	} | ||||
|  | ||||
| 	context.Command = c | ||||
| 	err = c.Action(context) | ||||
|  | ||||
| 	if err != nil { | ||||
| 		context.App.handleExitCoder(context, err) | ||||
| 	} | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (c *Command) newFlagSet() (*flag.FlagSet, error) { | ||||
| 	return flagSet(c.Name, c.Flags) | ||||
| } | ||||
|  | ||||
| func (c *Command) useShortOptionHandling() bool { | ||||
| 	return c.UseShortOptionHandling | ||||
| } | ||||
|  | ||||
| func (c *Command) parseFlags(args Args, shellComplete bool) (*flag.FlagSet, error) { | ||||
| 	set, err := c.newFlagSet() | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	if c.SkipFlagParsing { | ||||
| 		return set, set.Parse(append([]string{"--"}, args.Tail()...)) | ||||
| 	} | ||||
|  | ||||
| 	err = parseIter(set, c, args.Tail(), shellComplete) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	err = normalizeFlags(c.Flags, set) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return set, nil | ||||
| } | ||||
|  | ||||
| // Names returns the names including short names and aliases. | ||||
| func (c *Command) Names() []string { | ||||
| 	return append([]string{c.Name}, c.Aliases...) | ||||
| } | ||||
|  | ||||
| // HasName returns true if Command.Name matches given name | ||||
| func (c *Command) HasName(name string) bool { | ||||
| 	for _, n := range c.Names() { | ||||
| 		if n == name { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| func (c *Command) startApp(ctx *Context) error { | ||||
| 	app := &App{ | ||||
| 		Metadata: ctx.App.Metadata, | ||||
| 		Name:     fmt.Sprintf("%s %s", ctx.App.Name, c.Name), | ||||
| 	} | ||||
|  | ||||
| 	if c.HelpName == "" { | ||||
| 		app.HelpName = c.HelpName | ||||
| 	} else { | ||||
| 		app.HelpName = app.Name | ||||
| 	} | ||||
|  | ||||
| 	app.Usage = c.Usage | ||||
| 	app.Description = c.Description | ||||
| 	app.ArgsUsage = c.ArgsUsage | ||||
|  | ||||
| 	// set CommandNotFound | ||||
| 	app.CommandNotFound = ctx.App.CommandNotFound | ||||
| 	app.CustomAppHelpTemplate = c.CustomHelpTemplate | ||||
|  | ||||
| 	// set the flags and commands | ||||
| 	app.Commands = c.Subcommands | ||||
| 	app.Flags = c.Flags | ||||
| 	app.HideHelp = c.HideHelp | ||||
|  | ||||
| 	app.Version = ctx.App.Version | ||||
| 	app.HideVersion = ctx.App.HideVersion | ||||
| 	app.Compiled = ctx.App.Compiled | ||||
| 	app.Writer = ctx.App.Writer | ||||
| 	app.ErrWriter = ctx.App.ErrWriter | ||||
| 	app.ExitErrHandler = ctx.App.ExitErrHandler | ||||
| 	app.UseShortOptionHandling = ctx.App.UseShortOptionHandling | ||||
|  | ||||
| 	app.categories = newCommandCategories() | ||||
| 	for _, command := range c.Subcommands { | ||||
| 		app.categories.AddCommand(command.Category, command) | ||||
| 	} | ||||
|  | ||||
| 	sort.Sort(app.categories.(*commandCategories)) | ||||
|  | ||||
| 	// bash completion | ||||
| 	app.EnableBashCompletion = ctx.App.EnableBashCompletion | ||||
| 	if c.BashComplete != nil { | ||||
| 		app.BashComplete = c.BashComplete | ||||
| 	} | ||||
|  | ||||
| 	// set the actions | ||||
| 	app.Before = c.Before | ||||
| 	app.After = c.After | ||||
| 	if c.Action != nil { | ||||
| 		app.Action = c.Action | ||||
| 	} else { | ||||
| 		app.Action = helpSubcommand.Action | ||||
| 	} | ||||
| 	app.OnUsageError = c.OnUsageError | ||||
|  | ||||
| 	for index, cc := range app.Commands { | ||||
| 		app.Commands[index].commandNamePath = []string{c.Name, cc.Name} | ||||
| 	} | ||||
|  | ||||
| 	return app.RunAsSubcommand(ctx) | ||||
| } | ||||
|  | ||||
| // VisibleFlags returns a slice of the Flags with Hidden=false | ||||
| func (c *Command) VisibleFlags() []Flag { | ||||
| 	return visibleFlags(c.Flags) | ||||
| } | ||||
|  | ||||
| func (c *Command) appendFlag(fl Flag) { | ||||
| 	if !hasFlag(c.Flags, fl) { | ||||
| 		c.Flags = append(c.Flags, fl) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func hasCommand(commands []*Command, command *Command) bool { | ||||
| 	for _, existing := range commands { | ||||
| 		if command == existing { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return false | ||||
| } | ||||
							
								
								
									
										274
									
								
								vendor/github.com/urfave/cli/v2/context.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										274
									
								
								vendor/github.com/urfave/cli/v2/context.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,274 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // Context is a type that is passed through to | ||||
| // each Handler action in a cli application. Context | ||||
| // can be used to retrieve context-specific args and | ||||
| // parsed command-line options. | ||||
| type Context struct { | ||||
| 	context.Context | ||||
| 	App           *App | ||||
| 	Command       *Command | ||||
| 	shellComplete bool | ||||
| 	setFlags      map[string]bool | ||||
| 	flagSet       *flag.FlagSet | ||||
| 	parentContext *Context | ||||
| } | ||||
|  | ||||
| // NewContext creates a new context. For use in when invoking an App or Command action. | ||||
| func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context { | ||||
| 	c := &Context{App: app, flagSet: set, parentContext: parentCtx} | ||||
| 	if parentCtx != nil { | ||||
| 		c.Context = parentCtx.Context | ||||
| 		c.shellComplete = parentCtx.shellComplete | ||||
| 		if parentCtx.flagSet == nil { | ||||
| 			parentCtx.flagSet = &flag.FlagSet{} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	c.Command = &Command{} | ||||
|  | ||||
| 	if c.Context == nil { | ||||
| 		c.Context = context.Background() | ||||
| 	} | ||||
|  | ||||
| 	return c | ||||
| } | ||||
|  | ||||
| // NumFlags returns the number of flags set | ||||
| func (c *Context) NumFlags() int { | ||||
| 	return c.flagSet.NFlag() | ||||
| } | ||||
|  | ||||
| // Set sets a context flag to a value. | ||||
| func (c *Context) Set(name, value string) error { | ||||
| 	return c.flagSet.Set(name, value) | ||||
| } | ||||
|  | ||||
| // IsSet determines if the flag was actually set | ||||
| func (c *Context) IsSet(name string) bool { | ||||
| 	if fs := lookupFlagSet(name, c); fs != nil { | ||||
| 		if fs := lookupFlagSet(name, c); fs != nil { | ||||
| 			isSet := false | ||||
| 			fs.Visit(func(f *flag.Flag) { | ||||
| 				if f.Name == name { | ||||
| 					isSet = true | ||||
| 				} | ||||
| 			}) | ||||
| 			if isSet { | ||||
| 				return true | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		f := lookupFlag(name, c) | ||||
| 		if f == nil { | ||||
| 			return false | ||||
| 		} | ||||
|  | ||||
| 		return f.IsSet() | ||||
| 	} | ||||
|  | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // LocalFlagNames returns a slice of flag names used in this context. | ||||
| func (c *Context) LocalFlagNames() []string { | ||||
| 	var names []string | ||||
| 	c.flagSet.Visit(makeFlagNameVisitor(&names)) | ||||
| 	return names | ||||
| } | ||||
|  | ||||
| // FlagNames returns a slice of flag names used by the this context and all of | ||||
| // its parent contexts. | ||||
| func (c *Context) FlagNames() []string { | ||||
| 	var names []string | ||||
| 	for _, ctx := range c.Lineage() { | ||||
| 		ctx.flagSet.Visit(makeFlagNameVisitor(&names)) | ||||
| 	} | ||||
| 	return names | ||||
| } | ||||
|  | ||||
| // Lineage returns *this* context and all of its ancestor contexts in order from | ||||
| // child to parent | ||||
| func (c *Context) Lineage() []*Context { | ||||
| 	var lineage []*Context | ||||
|  | ||||
| 	for cur := c; cur != nil; cur = cur.parentContext { | ||||
| 		lineage = append(lineage, cur) | ||||
| 	} | ||||
|  | ||||
| 	return lineage | ||||
| } | ||||
|  | ||||
| // Value returns the value of the flag corresponding to `name` | ||||
| func (c *Context) Value(name string) interface{} { | ||||
| 	return c.flagSet.Lookup(name).Value.(flag.Getter).Get() | ||||
| } | ||||
|  | ||||
| // Args returns the command line arguments associated with the context. | ||||
| func (c *Context) Args() Args { | ||||
| 	ret := args(c.flagSet.Args()) | ||||
| 	return &ret | ||||
| } | ||||
|  | ||||
| // NArg returns the number of the command line arguments. | ||||
| func (c *Context) NArg() int { | ||||
| 	return c.Args().Len() | ||||
| } | ||||
|  | ||||
| func lookupFlag(name string, ctx *Context) Flag { | ||||
| 	for _, c := range ctx.Lineage() { | ||||
| 		if c.Command == nil { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		for _, f := range c.Command.Flags { | ||||
| 			for _, n := range f.Names() { | ||||
| 				if n == name { | ||||
| 					return f | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if ctx.App != nil { | ||||
| 		for _, f := range ctx.App.Flags { | ||||
| 			for _, n := range f.Names() { | ||||
| 				if n == name { | ||||
| 					return f | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupFlagSet(name string, ctx *Context) *flag.FlagSet { | ||||
| 	for _, c := range ctx.Lineage() { | ||||
| 		if f := c.flagSet.Lookup(name); f != nil { | ||||
| 			return c.flagSet | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) { | ||||
| 	switch ff.Value.(type) { | ||||
| 	case Serializer: | ||||
| 		_ = set.Set(name, ff.Value.(Serializer).Serialize()) | ||||
| 	default: | ||||
| 		_ = set.Set(name, ff.Value.String()) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func normalizeFlags(flags []Flag, set *flag.FlagSet) error { | ||||
| 	visited := make(map[string]bool) | ||||
| 	set.Visit(func(f *flag.Flag) { | ||||
| 		visited[f.Name] = true | ||||
| 	}) | ||||
| 	for _, f := range flags { | ||||
| 		parts := f.Names() | ||||
| 		if len(parts) == 1 { | ||||
| 			continue | ||||
| 		} | ||||
| 		var ff *flag.Flag | ||||
| 		for _, name := range parts { | ||||
| 			name = strings.Trim(name, " ") | ||||
| 			if visited[name] { | ||||
| 				if ff != nil { | ||||
| 					return errors.New("Cannot use two forms of the same flag: " + name + " " + ff.Name) | ||||
| 				} | ||||
| 				ff = set.Lookup(name) | ||||
| 			} | ||||
| 		} | ||||
| 		if ff == nil { | ||||
| 			continue | ||||
| 		} | ||||
| 		for _, name := range parts { | ||||
| 			name = strings.Trim(name, " ") | ||||
| 			if !visited[name] { | ||||
| 				copyFlag(name, ff, set) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func makeFlagNameVisitor(names *[]string) func(*flag.Flag) { | ||||
| 	return func(f *flag.Flag) { | ||||
| 		nameParts := strings.Split(f.Name, ",") | ||||
| 		name := strings.TrimSpace(nameParts[0]) | ||||
|  | ||||
| 		for _, part := range nameParts { | ||||
| 			part = strings.TrimSpace(part) | ||||
| 			if len(part) > len(name) { | ||||
| 				name = part | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if name != "" { | ||||
| 			*names = append(*names, name) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| 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() { | ||||
| 			var flagPresent bool | ||||
| 			var flagName string | ||||
|  | ||||
| 			for _, key := range f.Names() { | ||||
| 				if len(key) > 1 { | ||||
| 					flagName = key | ||||
| 				} | ||||
|  | ||||
| 				if context.IsSet(strings.TrimSpace(key)) { | ||||
| 					flagPresent = true | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			if !flagPresent && flagName != "" { | ||||
| 				missingFlags = append(missingFlags, flagName) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if len(missingFlags) != 0 { | ||||
| 		return &errRequiredFlags{missingFlags: missingFlags} | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										148
									
								
								vendor/github.com/urfave/cli/v2/docs.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								vendor/github.com/urfave/cli/v2/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.VisibleFlags()), | ||||
| 		SynopsisArgs: prepareArgsSynopsis(a.VisibleFlags()), | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func prepareCommands(commands []*Command, level int) []string { | ||||
| 	var coms []string | ||||
| 	for _, command := range commands { | ||||
| 		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 flag.Names() { | ||||
| 			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 | ||||
| } | ||||
							
								
								
									
										131
									
								
								vendor/github.com/urfave/cli/v2/errors.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										131
									
								
								vendor/github.com/urfave/cli/v2/errors.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,131 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"os" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // OsExiter is the function used when the app exits. If not set defaults to os.Exit. | ||||
| var OsExiter = os.Exit | ||||
|  | ||||
| // ErrWriter is used to write errors to the user. This can be anything | ||||
| // implementing the io.Writer interface and defaults to os.Stderr. | ||||
| var ErrWriter io.Writer = os.Stderr | ||||
|  | ||||
| // MultiError is an error that wraps multiple errors. | ||||
| type MultiError interface { | ||||
| 	error | ||||
| 	// Errors returns a copy of the errors slice | ||||
| 	Errors() []error | ||||
| } | ||||
|  | ||||
| // NewMultiError creates a new MultiError. Pass in one or more errors. | ||||
| func newMultiError(err ...error) MultiError { | ||||
| 	ret := multiError(err) | ||||
| 	return &ret | ||||
| } | ||||
|  | ||||
| type multiError []error | ||||
|  | ||||
| // Error implements the error interface. | ||||
| func (m *multiError) Error() string { | ||||
| 	errs := make([]string, len(*m)) | ||||
| 	for i, err := range *m { | ||||
| 		errs[i] = err.Error() | ||||
| 	} | ||||
|  | ||||
| 	return strings.Join(errs, "\n") | ||||
| } | ||||
|  | ||||
| // Errors returns a copy of the errors slice | ||||
| func (m *multiError) Errors() []error { | ||||
| 	errs := make([]error, len(*m)) | ||||
| 	for _, err := range *m { | ||||
| 		errs = append(errs, err) | ||||
| 	} | ||||
| 	return errs | ||||
| } | ||||
|  | ||||
| // ErrorFormatter is the interface that will suitably format the error output | ||||
| type ErrorFormatter interface { | ||||
| 	Format(s fmt.State, verb rune) | ||||
| } | ||||
|  | ||||
| // ExitCoder is the interface checked by `App` and `Command` for a custom exit | ||||
| // code | ||||
| type ExitCoder interface { | ||||
| 	error | ||||
| 	ExitCode() int | ||||
| } | ||||
|  | ||||
| type exitError struct { | ||||
| 	exitCode int | ||||
| 	message  interface{} | ||||
| } | ||||
|  | ||||
| // NewExitError makes a new *exitError | ||||
| func NewExitError(message interface{}, exitCode int) ExitCoder { | ||||
| 	return Exit(message, exitCode) | ||||
| } | ||||
|  | ||||
| // Exit wraps a message and exit code into an ExitCoder suitable for handling by | ||||
| // HandleExitCoder | ||||
| func Exit(message interface{}, exitCode int) ExitCoder { | ||||
| 	return &exitError{ | ||||
| 		message:  message, | ||||
| 		exitCode: exitCode, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (ee *exitError) Error() string { | ||||
| 	return fmt.Sprintf("%v", ee.message) | ||||
| } | ||||
|  | ||||
| func (ee *exitError) ExitCode() int { | ||||
| 	return ee.exitCode | ||||
| } | ||||
|  | ||||
| // HandleExitCoder checks if the error fulfills the ExitCoder interface, and if | ||||
| // so prints the error to stderr (if it is non-empty) and calls OsExiter with the | ||||
| // given exit code.  If the given error is a MultiError, then this func is | ||||
| // called on all members of the Errors slice and calls OsExiter with the last exit code. | ||||
| func HandleExitCoder(err error) { | ||||
| 	if err == nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if exitErr, ok := err.(ExitCoder); ok { | ||||
| 		if err.Error() != "" { | ||||
| 			if _, ok := exitErr.(ErrorFormatter); ok { | ||||
| 				_, _ = fmt.Fprintf(ErrWriter, "%+v\n", err) | ||||
| 			} else { | ||||
| 				_, _ = fmt.Fprintln(ErrWriter, err) | ||||
| 			} | ||||
| 		} | ||||
| 		OsExiter(exitErr.ExitCode()) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if multiErr, ok := err.(MultiError); ok { | ||||
| 		code := handleMultiError(multiErr) | ||||
| 		OsExiter(code) | ||||
| 		return | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func handleMultiError(multiErr MultiError) int { | ||||
| 	code := 1 | ||||
| 	for _, merr := range multiErr.Errors() { | ||||
| 		if multiErr2, ok := merr.(MultiError); ok { | ||||
| 			code = handleMultiError(multiErr2) | ||||
| 		} else if merr != nil { | ||||
| 			fmt.Fprintln(ErrWriter, merr) | ||||
| 			if exitErr, ok := merr.(ExitCoder); ok { | ||||
| 				code = exitErr.ExitCode() | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return code | ||||
| } | ||||
							
								
								
									
										192
									
								
								vendor/github.com/urfave/cli/v2/fish.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										192
									
								
								vendor/github.com/urfave/cli/v2/fish.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,192 @@ | ||||
| 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 _, command := range commands { | ||||
| 		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 flag.Names() { | ||||
| 			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) | ||||
| } | ||||
							
								
								
									
										398
									
								
								vendor/github.com/urfave/cli/v2/flag.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										398
									
								
								vendor/github.com/urfave/cli/v2/flag.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,398 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"reflect" | ||||
| 	"regexp" | ||||
| 	"runtime" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"syscall" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| const defaultPlaceholder = "value" | ||||
|  | ||||
| var ( | ||||
| 	slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano()) | ||||
|  | ||||
| 	commaWhitespace = regexp.MustCompile("[, ]+.*") | ||||
| ) | ||||
|  | ||||
| // BashCompletionFlag enables bash-completion for all commands and subcommands | ||||
| var BashCompletionFlag Flag = &BoolFlag{ | ||||
| 	Name:   "generate-bash-completion", | ||||
| 	Hidden: true, | ||||
| } | ||||
|  | ||||
| // VersionFlag prints the version for the application | ||||
| var VersionFlag Flag = &BoolFlag{ | ||||
| 	Name:    "version", | ||||
| 	Aliases: []string{"v"}, | ||||
| 	Usage:   "print the version", | ||||
| } | ||||
|  | ||||
| // HelpFlag prints the help for all commands and subcommands. | ||||
| // Set to nil to disable the flag.  The subcommand | ||||
| // will still be added unless HideHelp is set to true. | ||||
| var HelpFlag Flag = &BoolFlag{ | ||||
| 	Name:    "help", | ||||
| 	Aliases: []string{"h"}, | ||||
| 	Usage:   "show help", | ||||
| } | ||||
|  | ||||
| // FlagStringer converts a flag definition to a string. This is used by help | ||||
| // to display a flag. | ||||
| var FlagStringer FlagStringFunc = stringifyFlag | ||||
|  | ||||
| // Serializer is used to circumvent the limitations of flag.FlagSet.Set | ||||
| type Serializer interface { | ||||
| 	Serialize() string | ||||
| } | ||||
|  | ||||
| // FlagNamePrefixer converts a full flag name and its placeholder into the help | ||||
| // message flag prefix. This is used by the default FlagStringer. | ||||
| var FlagNamePrefixer FlagNamePrefixFunc = prefixedNames | ||||
|  | ||||
| // FlagEnvHinter annotates flag help message with the environment variable | ||||
| // 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 | ||||
|  | ||||
| func (f FlagsByName) Len() int { | ||||
| 	return len(f) | ||||
| } | ||||
|  | ||||
| func (f FlagsByName) Less(i, j int) bool { | ||||
| 	if len(f[j].Names()) == 0 { | ||||
| 		return false | ||||
| 	} else if len(f[i].Names()) == 0 { | ||||
| 		return true | ||||
| 	} | ||||
| 	return lexicographicLess(f[i].Names()[0], f[j].Names()[0]) | ||||
| } | ||||
|  | ||||
| func (f FlagsByName) Swap(i, j int) { | ||||
| 	f[i], f[j] = f[j], f[i] | ||||
| } | ||||
|  | ||||
| // Flag is a common interface related to parsing flags in cli. | ||||
| // For more advanced flag parsing techniques, it is recommended that | ||||
| // this interface be implemented. | ||||
| type Flag interface { | ||||
| 	fmt.Stringer | ||||
| 	// Apply Flag settings to the given flag set | ||||
| 	Apply(*flag.FlagSet) error | ||||
| 	Names() []string | ||||
| 	IsSet() bool | ||||
| } | ||||
|  | ||||
| // 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 if 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 | ||||
| } | ||||
|  | ||||
| func flagSet(name string, flags []Flag) (*flag.FlagSet, error) { | ||||
| 	set := flag.NewFlagSet(name, flag.ContinueOnError) | ||||
|  | ||||
| 	for _, f := range flags { | ||||
| 		if err := f.Apply(set); err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
| 	set.SetOutput(ioutil.Discard) | ||||
| 	return set, nil | ||||
| } | ||||
|  | ||||
| func visibleFlags(fl []Flag) []Flag { | ||||
| 	var visible []Flag | ||||
| 	for _, f := range fl { | ||||
| 		field := flagValue(f).FieldByName("Hidden") | ||||
| 		if !field.IsValid() || !field.Bool() { | ||||
| 			visible = append(visible, f) | ||||
| 		} | ||||
| 	} | ||||
| 	return visible | ||||
| } | ||||
|  | ||||
| func prefixFor(name string) (prefix string) { | ||||
| 	if len(name) == 1 { | ||||
| 		prefix = "-" | ||||
| 	} else { | ||||
| 		prefix = "--" | ||||
| 	} | ||||
|  | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // Returns the placeholder, if any, and the unquoted usage string. | ||||
| func unquoteUsage(usage string) (string, string) { | ||||
| 	for i := 0; i < len(usage); i++ { | ||||
| 		if usage[i] == '`' { | ||||
| 			for j := i + 1; j < len(usage); j++ { | ||||
| 				if usage[j] == '`' { | ||||
| 					name := usage[i+1 : j] | ||||
| 					usage = usage[:i] + name + usage[j+1:] | ||||
| 					return name, usage | ||||
| 				} | ||||
| 			} | ||||
| 			break | ||||
| 		} | ||||
| 	} | ||||
| 	return "", usage | ||||
| } | ||||
|  | ||||
| func prefixedNames(names []string, placeholder string) string { | ||||
| 	var prefixed string | ||||
| 	for i, name := range names { | ||||
| 		if name == "" { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		prefixed += prefixFor(name) + name | ||||
| 		if placeholder != "" { | ||||
| 			prefixed += " " + placeholder | ||||
| 		} | ||||
| 		if i < len(names)-1 { | ||||
| 			prefixed += ", " | ||||
| 		} | ||||
| 	} | ||||
| 	return prefixed | ||||
| } | ||||
|  | ||||
| func withEnvHint(envVars []string, str string) string { | ||||
| 	envText := "" | ||||
| 	if envVars != nil && len(envVars) > 0 { | ||||
| 		prefix := "$" | ||||
| 		suffix := "" | ||||
| 		sep := ", $" | ||||
| 		if runtime.GOOS == "windows" { | ||||
| 			prefix = "%" | ||||
| 			suffix = "%" | ||||
| 			sep = "%, %" | ||||
| 		} | ||||
|  | ||||
| 		envText = fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(envVars, sep), suffix) | ||||
| 	} | ||||
| 	return str + envText | ||||
| } | ||||
|  | ||||
| func flagNames(f Flag) []string { | ||||
| 	var ret []string | ||||
|  | ||||
| 	name := flagStringField(f, "Name") | ||||
| 	aliases := flagStringSliceField(f, "Aliases") | ||||
|  | ||||
| 	for _, part := range append([]string{name}, aliases...) { | ||||
| 		// v1 -> v2 migration warning zone: | ||||
| 		// Strip off anything after the first found comma or space, which | ||||
| 		// *hopefully* makes it a tiny bit more obvious that unexpected behavior is | ||||
| 		// caused by using the v1 form of stringly typed "Name". | ||||
| 		ret = append(ret, commaWhitespace.ReplaceAllString(part, "")) | ||||
| 	} | ||||
|  | ||||
| 	return ret | ||||
| } | ||||
|  | ||||
| func flagStringSliceField(f Flag, name string) []string { | ||||
| 	fv := flagValue(f) | ||||
| 	field := fv.FieldByName(name) | ||||
|  | ||||
| 	if field.IsValid() { | ||||
| 		return field.Interface().([]string) | ||||
| 	} | ||||
|  | ||||
| 	return []string{} | ||||
| } | ||||
|  | ||||
| func flagStringField(f Flag, name string) string { | ||||
| 	fv := flagValue(f) | ||||
| 	field := fv.FieldByName(name) | ||||
|  | ||||
| 	if field.IsValid() { | ||||
| 		return field.String() | ||||
| 	} | ||||
|  | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| 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 { | ||||
| 		fv = reflect.Indirect(fv) | ||||
| 	} | ||||
| 	return fv | ||||
| } | ||||
|  | ||||
| func stringifyFlag(f Flag) string { | ||||
| 	fv := flagValue(f) | ||||
|  | ||||
| 	switch f.(type) { | ||||
| 	case *IntSliceFlag: | ||||
| 		return withEnvHint(flagStringSliceField(f, "EnvVars"), | ||||
| 			stringifyIntSliceFlag(f.(*IntSliceFlag))) | ||||
| 	case *Int64SliceFlag: | ||||
| 		return withEnvHint(flagStringSliceField(f, "EnvVars"), | ||||
| 			stringifyInt64SliceFlag(f.(*Int64SliceFlag))) | ||||
| 	case *Float64SliceFlag: | ||||
| 		return withEnvHint(flagStringSliceField(f, "EnvVars"), | ||||
| 			stringifyFloat64SliceFlag(f.(*Float64SliceFlag))) | ||||
| 	case *StringSliceFlag: | ||||
| 		return withEnvHint(flagStringSliceField(f, "EnvVars"), | ||||
| 			stringifyStringSliceFlag(f.(*StringSliceFlag))) | ||||
| 	} | ||||
|  | ||||
| 	placeholder, usage := unquoteUsage(fv.FieldByName("Usage").String()) | ||||
|  | ||||
| 	needsPlaceholder := false | ||||
| 	defaultValueString := "" | ||||
| 	val := fv.FieldByName("Value") | ||||
| 	if val.IsValid() { | ||||
| 		needsPlaceholder = val.Kind() != reflect.Bool | ||||
| 		defaultValueString = fmt.Sprintf(" (default: %v)", val.Interface()) | ||||
|  | ||||
| 		if val.Kind() == reflect.String && val.String() != "" { | ||||
| 			defaultValueString = fmt.Sprintf(" (default: %q)", val.String()) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	helpText := fv.FieldByName("DefaultText") | ||||
| 	if helpText.IsValid() && helpText.String() != "" { | ||||
| 		needsPlaceholder = val.Kind() != reflect.Bool | ||||
| 		defaultValueString = fmt.Sprintf(" (default: %s)", helpText.String()) | ||||
| 	} | ||||
|  | ||||
| 	if defaultValueString == " (default: )" { | ||||
| 		defaultValueString = "" | ||||
| 	} | ||||
|  | ||||
| 	if needsPlaceholder && placeholder == "" { | ||||
| 		placeholder = defaultPlaceholder | ||||
| 	} | ||||
|  | ||||
| 	usageWithDefault := strings.TrimSpace(usage + defaultValueString) | ||||
|  | ||||
| 	return withEnvHint(flagStringSliceField(f, "EnvVars"), | ||||
| 		fmt.Sprintf("%s\t%s", prefixedNames(f.Names(), placeholder), usageWithDefault)) | ||||
| } | ||||
|  | ||||
| func stringifyIntSliceFlag(f *IntSliceFlag) string { | ||||
| 	var defaultVals []string | ||||
| 	if f.Value != nil && len(f.Value.Value()) > 0 { | ||||
| 		for _, i := range f.Value.Value() { | ||||
| 			defaultVals = append(defaultVals, strconv.Itoa(i)) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return stringifySliceFlag(f.Usage, f.Names(), defaultVals) | ||||
| } | ||||
|  | ||||
| func stringifyInt64SliceFlag(f *Int64SliceFlag) string { | ||||
| 	var defaultVals []string | ||||
| 	if f.Value != nil && len(f.Value.Value()) > 0 { | ||||
| 		for _, i := range f.Value.Value() { | ||||
| 			defaultVals = append(defaultVals, strconv.FormatInt(i, 10)) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return stringifySliceFlag(f.Usage, f.Names(), defaultVals) | ||||
| } | ||||
|  | ||||
| func stringifyFloat64SliceFlag(f *Float64SliceFlag) string { | ||||
| 	var defaultVals []string | ||||
|  | ||||
| 	if f.Value != nil && len(f.Value.Value()) > 0 { | ||||
| 		for _, i := range f.Value.Value() { | ||||
| 			defaultVals = append(defaultVals, strings.TrimRight(strings.TrimRight(fmt.Sprintf("%f", i), "0"), ".")) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return stringifySliceFlag(f.Usage, f.Names(), defaultVals) | ||||
| } | ||||
|  | ||||
| func stringifyStringSliceFlag(f *StringSliceFlag) 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, strconv.Quote(s)) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return stringifySliceFlag(f.Usage, f.Names(), defaultVals) | ||||
| } | ||||
|  | ||||
| func stringifySliceFlag(usage string, names, defaultVals []string) string { | ||||
| 	placeholder, usage := unquoteUsage(usage) | ||||
| 	if placeholder == "" { | ||||
| 		placeholder = defaultPlaceholder | ||||
| 	} | ||||
|  | ||||
| 	defaultVal := "" | ||||
| 	if len(defaultVals) > 0 { | ||||
| 		defaultVal = fmt.Sprintf(" (default: %s)", strings.Join(defaultVals, ", ")) | ||||
| 	} | ||||
|  | ||||
| 	usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultVal)) | ||||
| 	return fmt.Sprintf("%s\t%s", prefixedNames(names, placeholder), usageWithDefault) | ||||
| } | ||||
|  | ||||
| func hasFlag(flags []Flag, fl Flag) bool { | ||||
| 	for _, existing := range flags { | ||||
| 		if fl == existing { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| func flagFromEnvOrFile(envVars []string, filePath string) (val string, ok bool) { | ||||
| 	for _, envVar := range envVars { | ||||
| 		envVar = strings.TrimSpace(envVar) | ||||
| 		if val, ok := syscall.Getenv(envVar); ok { | ||||
| 			return val, true | ||||
| 		} | ||||
| 	} | ||||
| 	for _, fileVar := range strings.Split(filePath, ",") { | ||||
| 		if data, err := ioutil.ReadFile(fileVar); err == nil { | ||||
| 			return string(data), true | ||||
| 		} | ||||
| 	} | ||||
| 	return "", false | ||||
| } | ||||
							
								
								
									
										106
									
								
								vendor/github.com/urfave/cli/v2/flag_bool.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								vendor/github.com/urfave/cli/v2/flag_bool.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // BoolFlag is a flag with type bool | ||||
| type BoolFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       bool | ||||
| 	DefaultText string | ||||
| 	Destination *bool | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *BoolFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *BoolFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *BoolFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 "" | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| func (f *BoolFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if val != "" { | ||||
| 			valBool, err := strconv.ParseBool(val) | ||||
|  | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as bool value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
|  | ||||
| 			f.Value = valBool | ||||
| 			f.HasBeenSet = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Destination != nil { | ||||
| 			set.BoolVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			continue | ||||
| 		} | ||||
| 		set.Bool(name, f.Value, f.Usage) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Bool looks up the value of a local BoolFlag, returns | ||||
| // false if not found | ||||
| func (c *Context) Bool(name string) bool { | ||||
| 	if fs := lookupFlagSet(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 | ||||
| } | ||||
							
								
								
									
										105
									
								
								vendor/github.com/urfave/cli/v2/flag_duration.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								vendor/github.com/urfave/cli/v2/flag_duration.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | ||||
| 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 | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       time.Duration | ||||
| 	DefaultText string | ||||
| 	Destination *time.Duration | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *DurationFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *DurationFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *DurationFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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() | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| func (f *DurationFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if val != "" { | ||||
| 			valDuration, err := time.ParseDuration(val) | ||||
|  | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as duration value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
|  | ||||
| 			f.Value = valDuration | ||||
| 			f.HasBeenSet = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Destination != nil { | ||||
| 			set.DurationVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			continue | ||||
| 		} | ||||
| 		set.Duration(name, f.Value, f.Usage) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Duration looks up the value of a local DurationFlag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Duration(name string) time.Duration { | ||||
| 	if fs := lookupFlagSet(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 | ||||
| } | ||||
							
								
								
									
										106
									
								
								vendor/github.com/urfave/cli/v2/flag_float64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								vendor/github.com/urfave/cli/v2/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 | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       float64 | ||||
| 	DefaultText string | ||||
| 	Destination *float64 | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *Float64Flag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *Float64Flag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *Float64Flag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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) | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| func (f *Float64Flag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if val != "" { | ||||
| 			valFloat, err := strconv.ParseFloat(val, 10) | ||||
|  | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as float64 value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
|  | ||||
| 			f.Value = valFloat | ||||
| 			f.HasBeenSet = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Destination != nil { | ||||
| 			set.Float64Var(f.Destination, name, f.Value, f.Usage) | ||||
| 			continue | ||||
| 		} | ||||
| 		set.Float64(name, f.Value, f.Usage) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Float64 looks up the value of a local Float64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Float64(name string) float64 { | ||||
| 	if fs := lookupFlagSet(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 | ||||
| } | ||||
							
								
								
									
										165
									
								
								vendor/github.com/urfave/cli/v2/flag_float64_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										165
									
								
								vendor/github.com/urfave/cli/v2/flag_float64_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,165 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // Float64Slice wraps []float64 to satisfy flag.Value | ||||
| type Float64Slice struct { | ||||
| 	slice      []float64 | ||||
| 	hasBeenSet bool | ||||
| } | ||||
|  | ||||
| // NewFloat64Slice makes a *Float64Slice with default values | ||||
| func NewFloat64Slice(defaults ...float64) *Float64Slice { | ||||
| 	return &Float64Slice{slice: append([]float64{}, defaults...)} | ||||
| } | ||||
|  | ||||
| // Set parses the value into a float64 and appends it to the list of values | ||||
| func (f *Float64Slice) Set(value string) error { | ||||
| 	if !f.hasBeenSet { | ||||
| 		f.slice = []float64{} | ||||
| 		f.hasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	if strings.HasPrefix(value, slPfx) { | ||||
| 		// Deserializing assumes overwrite | ||||
| 		_ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &f.slice) | ||||
| 		f.hasBeenSet = true | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	tmp, err := strconv.ParseFloat(value, 64) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	f.slice = append(f.slice, tmp) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (f *Float64Slice) String() string { | ||||
| 	return fmt.Sprintf("%#v", f.slice) | ||||
| } | ||||
|  | ||||
| // Serialize allows Float64Slice to fulfill Serializer | ||||
| func (f *Float64Slice) Serialize() string { | ||||
| 	jsonBytes, _ := json.Marshal(f.slice) | ||||
| 	return fmt.Sprintf("%s%s", slPfx, string(jsonBytes)) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of float64s set by this flag | ||||
| func (f *Float64Slice) Value() []float64 { | ||||
| 	return f.slice | ||||
| } | ||||
|  | ||||
| // Get returns the slice of float64s set by this flag | ||||
| func (f *Float64Slice) Get() interface{} { | ||||
| 	return *f | ||||
| } | ||||
|  | ||||
| // Float64SliceFlag is a flag with type *Float64Slice | ||||
| type Float64SliceFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       *Float64Slice | ||||
| 	DefaultText string | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *Float64SliceFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *Float64SliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *Float64SliceFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f *Float64SliceFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true if the flag takes a value, otherwise false | ||||
| func (f *Float64SliceFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f *Float64SliceFlag) 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 *Float64SliceFlag) GetValue() string { | ||||
| 	if f.Value != nil { | ||||
| 		return f.Value.String() | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if val != "" { | ||||
| 			f.Value = &Float64Slice{} | ||||
|  | ||||
| 			for _, s := range strings.Split(val, ",") { | ||||
| 				if err := f.Value.Set(strings.TrimSpace(s)); err != nil { | ||||
| 					return fmt.Errorf("could not parse %q as float64 slice value for flag %s: %s", f.Value, f.Name, err) | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			f.HasBeenSet = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Value == nil { | ||||
| 			f.Value = &Float64Slice{} | ||||
| 		} | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Float64Slice looks up the value of a local Float64SliceFlag, returns | ||||
| // nil if not found | ||||
| func (c *Context) Float64Slice(name string) []float64 { | ||||
| 	if fs := lookupFlagSet(name, c); fs != nil { | ||||
| 		return lookupFloat64Slice(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func lookupFloat64Slice(name string, set *flag.FlagSet) []float64 { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		parsed, err := (f.Value.(*Float64Slice)).Value(), error(nil) | ||||
| 		if err != nil { | ||||
| 			return nil | ||||
| 		} | ||||
| 		return parsed | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										108
									
								
								vendor/github.com/urfave/cli/v2/flag_generic.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								vendor/github.com/urfave/cli/v2/flag_generic.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,108 @@ | ||||
| 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 | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	TakesFile   bool | ||||
| 	Value       Generic | ||||
| 	DefaultText string | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *GenericFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *GenericFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *GenericFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| func (f GenericFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if val != "" { | ||||
| 			if err := f.Value.Set(val); err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
|  | ||||
| 			f.HasBeenSet = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		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{} { | ||||
| 	if fs := lookupFlagSet(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 | ||||
| } | ||||
							
								
								
									
										106
									
								
								vendor/github.com/urfave/cli/v2/flag_int.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								vendor/github.com/urfave/cli/v2/flag_int.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // IntFlag is a flag with type int | ||||
| type IntFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       int | ||||
| 	DefaultText string | ||||
| 	Destination *int | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *IntFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *IntFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *IntFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| func (f *IntFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if val != "" { | ||||
| 			valInt, err := strconv.ParseInt(val, 0, 64) | ||||
|  | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as int value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
|  | ||||
| 			f.Value = int(valInt) | ||||
| 			f.HasBeenSet = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Destination != nil { | ||||
| 			set.IntVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			continue | ||||
| 		} | ||||
| 		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 { | ||||
| 	if fs := lookupFlagSet(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 | ||||
| } | ||||
							
								
								
									
										105
									
								
								vendor/github.com/urfave/cli/v2/flag_int64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								vendor/github.com/urfave/cli/v2/flag_int64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // Int64Flag is a flag with type int64 | ||||
| type Int64Flag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       int64 | ||||
| 	DefaultText string | ||||
| 	Destination *int64 | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *Int64Flag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *Int64Flag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *Int64Flag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| func (f *Int64Flag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if val != "" { | ||||
| 			valInt, err := strconv.ParseInt(val, 0, 64) | ||||
|  | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as int value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
|  | ||||
| 			f.Value = valInt | ||||
| 			f.HasBeenSet = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Destination != nil { | ||||
| 			set.Int64Var(f.Destination, name, f.Value, f.Usage) | ||||
| 			continue | ||||
| 		} | ||||
| 		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 { | ||||
| 	if fs := lookupFlagSet(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 | ||||
| } | ||||
							
								
								
									
										161
									
								
								vendor/github.com/urfave/cli/v2/flag_int64_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										161
									
								
								vendor/github.com/urfave/cli/v2/flag_int64_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,161 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // Int64Slice wraps []int64 to satisfy flag.Value | ||||
| type Int64Slice struct { | ||||
| 	slice      []int64 | ||||
| 	hasBeenSet bool | ||||
| } | ||||
|  | ||||
| // NewInt64Slice makes an *Int64Slice with default values | ||||
| func NewInt64Slice(defaults ...int64) *Int64Slice { | ||||
| 	return &Int64Slice{slice: append([]int64{}, defaults...)} | ||||
| } | ||||
|  | ||||
| // Set parses the value into an integer and appends it to the list of values | ||||
| func (i *Int64Slice) Set(value string) error { | ||||
| 	if !i.hasBeenSet { | ||||
| 		i.slice = []int64{} | ||||
| 		i.hasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	if strings.HasPrefix(value, slPfx) { | ||||
| 		// Deserializing assumes overwrite | ||||
| 		_ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &i.slice) | ||||
| 		i.hasBeenSet = true | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	tmp, err := strconv.ParseInt(value, 0, 64) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	i.slice = append(i.slice, tmp) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (i *Int64Slice) String() string { | ||||
| 	return fmt.Sprintf("%#v", i.slice) | ||||
| } | ||||
|  | ||||
| // Serialize allows Int64Slice to fulfill Serializer | ||||
| func (i *Int64Slice) Serialize() string { | ||||
| 	jsonBytes, _ := json.Marshal(i.slice) | ||||
| 	return fmt.Sprintf("%s%s", slPfx, string(jsonBytes)) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of ints set by this flag | ||||
| func (i *Int64Slice) Value() []int64 { | ||||
| 	return i.slice | ||||
| } | ||||
|  | ||||
| // Get returns the slice of ints set by this flag | ||||
| func (i *Int64Slice) Get() interface{} { | ||||
| 	return *i | ||||
| } | ||||
|  | ||||
| // Int64SliceFlag is a flag with type *Int64Slice | ||||
| type Int64SliceFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       *Int64Slice | ||||
| 	DefaultText string | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *Int64SliceFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *Int64SliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *Int64SliceFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		f.Value = &Int64Slice{} | ||||
|  | ||||
| 		for _, s := range strings.Split(val, ",") { | ||||
| 			if err := f.Value.Set(strings.TrimSpace(s)); err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as int64 slice value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		f.HasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		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) | ||||
| } | ||||
|  | ||||
| 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 | ||||
| } | ||||
							
								
								
									
										175
									
								
								vendor/github.com/urfave/cli/v2/flag_int_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										175
									
								
								vendor/github.com/urfave/cli/v2/flag_int_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,175 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // IntSlice wraps []int to satisfy flag.Value | ||||
| type IntSlice struct { | ||||
| 	slice      []int | ||||
| 	hasBeenSet bool | ||||
| } | ||||
|  | ||||
| // NewIntSlice makes an *IntSlice with default values | ||||
| func NewIntSlice(defaults ...int) *IntSlice { | ||||
| 	return &IntSlice{slice: append([]int{}, defaults...)} | ||||
| } | ||||
|  | ||||
| // TODO: Consistently have specific Set function for Int64 and Float64 ? | ||||
| // SetInt directly adds an integer to the list of values | ||||
| func (i *IntSlice) SetInt(value int) { | ||||
| 	if !i.hasBeenSet { | ||||
| 		i.slice = []int{} | ||||
| 		i.hasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	i.slice = append(i.slice, value) | ||||
| } | ||||
|  | ||||
| // Set parses the value into an integer and appends it to the list of values | ||||
| func (i *IntSlice) Set(value string) error { | ||||
| 	if !i.hasBeenSet { | ||||
| 		i.slice = []int{} | ||||
| 		i.hasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	if strings.HasPrefix(value, slPfx) { | ||||
| 		// Deserializing assumes overwrite | ||||
| 		_ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &i.slice) | ||||
| 		i.hasBeenSet = true | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	tmp, err := strconv.ParseInt(value, 0, 64) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	i.slice = append(i.slice, int(tmp)) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (i *IntSlice) String() string { | ||||
| 	return fmt.Sprintf("%#v", i.slice) | ||||
| } | ||||
|  | ||||
| // Serialize allows IntSlice to fulfill Serializer | ||||
| func (i *IntSlice) Serialize() string { | ||||
| 	jsonBytes, _ := json.Marshal(i.slice) | ||||
| 	return fmt.Sprintf("%s%s", slPfx, string(jsonBytes)) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of ints set by this flag | ||||
| func (i *IntSlice) Value() []int { | ||||
| 	return i.slice | ||||
| } | ||||
|  | ||||
| // Get returns the slice of ints set by this flag | ||||
| func (i *IntSlice) Get() interface{} { | ||||
| 	return *i | ||||
| } | ||||
|  | ||||
| // IntSliceFlag is a flag with type *IntSlice | ||||
| type IntSliceFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       *IntSlice | ||||
| 	DefaultText string | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *IntSliceFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *IntSliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *IntSliceFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| func (f *IntSliceFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		f.Value = &IntSlice{} | ||||
|  | ||||
| 		for _, s := range strings.Split(val, ",") { | ||||
| 			if err := f.Value.Set(strings.TrimSpace(s)); err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as int slice value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		f.HasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		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 { | ||||
| 	if fs := lookupFlagSet(name, c); fs != nil { | ||||
| 		return lookupIntSlice(name, c.flagSet) | ||||
| 	} | ||||
| 	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 | ||||
| } | ||||
							
								
								
									
										95
									
								
								vendor/github.com/urfave/cli/v2/flag_path.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								vendor/github.com/urfave/cli/v2/flag_path.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,95 @@ | ||||
| package cli | ||||
|  | ||||
| import "flag" | ||||
|  | ||||
| type PathFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	TakesFile   bool | ||||
| 	Value       string | ||||
| 	DefaultText string | ||||
| 	Destination *string | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *PathFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *PathFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *PathFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f *PathFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f *PathFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f *PathFlag) 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 *PathFlag) GetValue() string { | ||||
| 	return f.Value | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| func (f *PathFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		f.Value = val | ||||
| 		f.HasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Destination != nil { | ||||
| 			set.StringVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			continue | ||||
| 		} | ||||
| 		set.String(name, f.Value, f.Usage) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Path looks up the value of a local PathFlag, returns | ||||
| // "" if not found | ||||
| func (c *Context) Path(name string) string { | ||||
| 	if fs := lookupFlagSet(name, c); fs != nil { | ||||
| 		return lookupPath(name, fs) | ||||
| 	} | ||||
|  | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| func lookupPath(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 "" | ||||
| } | ||||
							
								
								
									
										95
									
								
								vendor/github.com/urfave/cli/v2/flag_string.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								vendor/github.com/urfave/cli/v2/flag_string.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,95 @@ | ||||
| package cli | ||||
|  | ||||
| import "flag" | ||||
|  | ||||
| // StringFlag is a flag with type string | ||||
| type StringFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	TakesFile   bool | ||||
| 	Value       string | ||||
| 	DefaultText string | ||||
| 	Destination *string | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *StringFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *StringFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *StringFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| func (f *StringFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		f.Value = val | ||||
| 		f.HasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Destination != nil { | ||||
| 			set.StringVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			continue | ||||
| 		} | ||||
| 		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 { | ||||
| 	if fs := lookupFlagSet(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 "" | ||||
| } | ||||
							
								
								
									
										159
									
								
								vendor/github.com/urfave/cli/v2/flag_string_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										159
									
								
								vendor/github.com/urfave/cli/v2/flag_string_slice.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,159 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| // StringSlice wraps a []string to satisfy flag.Value | ||||
| type StringSlice struct { | ||||
| 	slice      []string | ||||
| 	hasBeenSet bool | ||||
| } | ||||
|  | ||||
| // NewStringSlice creates a *StringSlice with default values | ||||
| func NewStringSlice(defaults ...string) *StringSlice { | ||||
| 	return &StringSlice{slice: append([]string{}, defaults...)} | ||||
| } | ||||
|  | ||||
| // Set appends the string value to the list of values | ||||
| func (s *StringSlice) Set(value string) error { | ||||
| 	if !s.hasBeenSet { | ||||
| 		s.slice = []string{} | ||||
| 		s.hasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	if strings.HasPrefix(value, slPfx) { | ||||
| 		// Deserializing assumes overwrite | ||||
| 		_ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &s.slice) | ||||
| 		s.hasBeenSet = true | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	s.slice = append(s.slice, value) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (s *StringSlice) String() string { | ||||
| 	return fmt.Sprintf("%s", s.slice) | ||||
| } | ||||
|  | ||||
| // Serialize allows StringSlice to fulfill Serializer | ||||
| func (s *StringSlice) Serialize() string { | ||||
| 	jsonBytes, _ := json.Marshal(s.slice) | ||||
| 	return fmt.Sprintf("%s%s", slPfx, string(jsonBytes)) | ||||
| } | ||||
|  | ||||
| // Value returns the slice of strings set by this flag | ||||
| func (s *StringSlice) Value() []string { | ||||
| 	return s.slice | ||||
| } | ||||
|  | ||||
| // Get returns the slice of strings set by this flag | ||||
| func (s *StringSlice) Get() interface{} { | ||||
| 	return *s | ||||
| } | ||||
|  | ||||
| // StringSliceFlag is a flag with type *StringSlice | ||||
| type StringSliceFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	TakesFile   bool | ||||
| 	Value       *StringSlice | ||||
| 	DefaultText string | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *StringSliceFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *StringSliceFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *StringSliceFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| func (f *StringSliceFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		f.Value = &StringSlice{} | ||||
|  | ||||
| 		for _, s := range strings.Split(val, ",") { | ||||
| 			if err := f.Value.Set(strings.TrimSpace(s)); err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as string value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		f.HasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		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 { | ||||
| 	if fs := lookupFlagSet(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 | ||||
| } | ||||
							
								
								
									
										152
									
								
								vendor/github.com/urfave/cli/v2/flag_timestamp.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										152
									
								
								vendor/github.com/urfave/cli/v2/flag_timestamp.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,152 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| // Timestamp wrap to satisfy golang's flag interface. | ||||
| type Timestamp struct { | ||||
| 	timestamp  *time.Time | ||||
| 	hasBeenSet bool | ||||
| 	layout     string | ||||
| } | ||||
|  | ||||
| // Timestamp constructor | ||||
| func NewTimestamp(timestamp time.Time) *Timestamp { | ||||
| 	return &Timestamp{timestamp: ×tamp} | ||||
| } | ||||
|  | ||||
| // Set the timestamp value directly | ||||
| func (t *Timestamp) SetTimestamp(value time.Time) { | ||||
| 	if !t.hasBeenSet { | ||||
| 		t.timestamp = &value | ||||
| 		t.hasBeenSet = true | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Set the timestamp string layout for future parsing | ||||
| func (t *Timestamp) SetLayout(layout string) { | ||||
| 	t.layout = layout | ||||
| } | ||||
|  | ||||
| // Parses the string value to timestamp | ||||
| func (t *Timestamp) Set(value string) error { | ||||
| 	timestamp, err := time.Parse(t.layout, value) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	t.timestamp = ×tamp | ||||
| 	t.hasBeenSet = true | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value (for usage defaults) | ||||
| func (t *Timestamp) String() string { | ||||
| 	return fmt.Sprintf("%#v", t.timestamp) | ||||
| } | ||||
|  | ||||
| // Value returns the timestamp value stored in the flag | ||||
| func (t *Timestamp) Value() *time.Time { | ||||
| 	return t.timestamp | ||||
| } | ||||
|  | ||||
| // Get returns the flag structure | ||||
| func (t *Timestamp) Get() interface{} { | ||||
| 	return *t | ||||
| } | ||||
|  | ||||
| // TimestampFlag is a flag with type time | ||||
| type TimestampFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Layout      string | ||||
| 	Value       *Timestamp | ||||
| 	DefaultText string | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *TimestampFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *TimestampFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *TimestampFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // IsRequired returns whether or not the flag is required | ||||
| func (f *TimestampFlag) IsRequired() bool { | ||||
| 	return f.Required | ||||
| } | ||||
|  | ||||
| // TakesValue returns true of the flag takes a value, otherwise false | ||||
| func (f *TimestampFlag) TakesValue() bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| // GetUsage returns the usage string for the flag | ||||
| func (f *TimestampFlag) 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 *TimestampFlag) GetValue() string { | ||||
| 	if f.Value != nil { | ||||
| 		return f.Value.timestamp.String() | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| func (f *TimestampFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if f.Layout == "" { | ||||
| 		return fmt.Errorf("timestamp Layout is required") | ||||
| 	} | ||||
| 	f.Value = &Timestamp{} | ||||
| 	f.Value.SetLayout(f.Layout) | ||||
|  | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if err := f.Value.Set(val); err != nil { | ||||
| 			return fmt.Errorf("could not parse %q as timestamp value for flag %s: %s", val, f.Name, err) | ||||
| 		} | ||||
| 		f.HasBeenSet = true | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		set.Var(f.Value, name, f.Usage) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Timestamp gets the timestamp from a flag name | ||||
| func (c *Context) Timestamp(name string) *time.Time { | ||||
| 	if fs := lookupFlagSet(name, c); fs != nil { | ||||
| 		return lookupTimestamp(name, fs) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Fetches the timestamp value from the local timestampWrap | ||||
| func lookupTimestamp(name string, set *flag.FlagSet) *time.Time { | ||||
| 	f := set.Lookup(name) | ||||
| 	if f != nil { | ||||
| 		return (f.Value.(*Timestamp)).Value() | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										105
									
								
								vendor/github.com/urfave/cli/v2/flag_uint.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								vendor/github.com/urfave/cli/v2/flag_uint.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // UintFlag is a flag with type uint | ||||
| type UintFlag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       uint | ||||
| 	DefaultText string | ||||
| 	Destination *uint | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *UintFlag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *UintFlag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *UintFlag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| func (f *UintFlag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if val != "" { | ||||
| 			valInt, err := strconv.ParseUint(val, 0, 64) | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as uint value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
|  | ||||
| 			f.Value = uint(valInt) | ||||
| 			f.HasBeenSet = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Destination != nil { | ||||
| 			set.UintVar(f.Destination, name, f.Value, f.Usage) | ||||
| 			continue | ||||
| 		} | ||||
| 		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 { | ||||
| 	if fs := lookupFlagSet(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 | ||||
| } | ||||
							
								
								
									
										105
									
								
								vendor/github.com/urfave/cli/v2/flag_uint64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								vendor/github.com/urfave/cli/v2/flag_uint64.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| // Uint64Flag is a flag with type uint64 | ||||
| type Uint64Flag struct { | ||||
| 	Name        string | ||||
| 	Aliases     []string | ||||
| 	Usage       string | ||||
| 	EnvVars     []string | ||||
| 	FilePath    string | ||||
| 	Required    bool | ||||
| 	Hidden      bool | ||||
| 	Value       uint64 | ||||
| 	DefaultText string | ||||
| 	Destination *uint64 | ||||
| 	HasBeenSet  bool | ||||
| } | ||||
|  | ||||
| // IsSet returns whether or not the flag has been set through env or file | ||||
| func (f *Uint64Flag) IsSet() bool { | ||||
| 	return f.HasBeenSet | ||||
| } | ||||
|  | ||||
| // String returns a readable representation of this value | ||||
| // (for usage defaults) | ||||
| func (f *Uint64Flag) String() string { | ||||
| 	return FlagStringer(f) | ||||
| } | ||||
|  | ||||
| // Names returns the names of the flag | ||||
| func (f *Uint64Flag) Names() []string { | ||||
| 	return flagNames(f) | ||||
| } | ||||
|  | ||||
| // 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 | ||||
| } | ||||
|  | ||||
| // Apply populates the flag given the flag set and environment | ||||
| func (f *Uint64Flag) Apply(set *flag.FlagSet) error { | ||||
| 	if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { | ||||
| 		if val != "" { | ||||
| 			valInt, err := strconv.ParseUint(val, 0, 64) | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("could not parse %q as uint64 value for flag %s: %s", val, f.Name, err) | ||||
| 			} | ||||
|  | ||||
| 			f.Value = valInt | ||||
| 			f.HasBeenSet = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, name := range f.Names() { | ||||
| 		if f.Destination != nil { | ||||
| 			set.Uint64Var(f.Destination, name, f.Value, f.Usage) | ||||
| 			continue | ||||
| 		} | ||||
| 		set.Uint64(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 *Uint64Flag) GetValue() string { | ||||
| 	return fmt.Sprintf("%d", f.Value) | ||||
| } | ||||
|  | ||||
| // Uint64 looks up the value of a local Uint64Flag, returns | ||||
| // 0 if not found | ||||
| func (c *Context) Uint64(name string) uint64 { | ||||
| 	if fs := lookupFlagSet(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 | ||||
| } | ||||
							
								
								
									
										44
									
								
								vendor/github.com/urfave/cli/v2/funcs.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								vendor/github.com/urfave/cli/v2/funcs.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| package cli | ||||
|  | ||||
| // BashCompleteFunc is an action to execute when the shell completion flag is set | ||||
| type BashCompleteFunc func(*Context) | ||||
|  | ||||
| // BeforeFunc is an action to execute before any subcommands are run, but after | ||||
| // the context is ready if a non-nil error is returned, no subcommands are run | ||||
| type BeforeFunc func(*Context) error | ||||
|  | ||||
| // AfterFunc is an action to execute after any subcommands are run, but after the | ||||
| // subcommand has finished it is run even if Action() panics | ||||
| type AfterFunc func(*Context) error | ||||
|  | ||||
| // ActionFunc is the action to execute when no subcommands are specified | ||||
| type ActionFunc func(*Context) error | ||||
|  | ||||
| // CommandNotFoundFunc is executed if the proper command cannot be found | ||||
| type CommandNotFoundFunc func(*Context, string) | ||||
|  | ||||
| // OnUsageErrorFunc is executed if an usage error occurs. This is useful for displaying | ||||
| // customized usage error messages.  This function is able to replace the | ||||
| // original error messages.  If this function is not set, the "Incorrect usage" | ||||
| // is displayed and the execution is interrupted. | ||||
| type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error | ||||
|  | ||||
| // ExitErrHandlerFunc is executed if provided in order to handle exitError values | ||||
| // returned by Actions and Before/After functions. | ||||
| type ExitErrHandlerFunc func(context *Context, err error) | ||||
|  | ||||
| // FlagStringFunc is used by the help generation to display a flag, which is | ||||
| // expected to be a single line. | ||||
| type FlagStringFunc func(Flag) string | ||||
|  | ||||
| // FlagNamePrefixFunc is used by the default FlagStringFunc to create prefix | ||||
| // text for a flag's full name. | ||||
| type FlagNamePrefixFunc func(fullName []string, placeholder string) string | ||||
|  | ||||
| // FlagEnvHintFunc is used by the default FlagStringFunc to annotate flag help | ||||
| // with the environment variable details. | ||||
| type FlagEnvHintFunc func(envVars []string, 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/v2/go.mod
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								vendor/github.com/urfave/cli/v2/go.mod
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| module github.com/urfave/cli/v2 | ||||
|  | ||||
| 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 | ||||
| ) | ||||
							
								
								
									
										14
									
								
								vendor/github.com/urfave/cli/v2/go.sum
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								vendor/github.com/urfave/cli/v2/go.sum
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= | ||||
| github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||||
| github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= | ||||
| github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= | ||||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= | ||||
| github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||||
| github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= | ||||
| github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||||
| gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||||
							
								
								
									
										368
									
								
								vendor/github.com/urfave/cli/v2/help.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										368
									
								
								vendor/github.com/urfave/cli/v2/help.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,368 @@ | ||||
| package cli | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"os" | ||||
| 	"strings" | ||||
| 	"text/tabwriter" | ||||
| 	"text/template" | ||||
| 	"unicode/utf8" | ||||
| ) | ||||
|  | ||||
| var helpCommand = &Command{ | ||||
| 	Name:      "help", | ||||
| 	Aliases:   []string{"h"}, | ||||
| 	Usage:     "Shows a list of commands or help for one command", | ||||
| 	ArgsUsage: "[command]", | ||||
| 	Action: func(c *Context) error { | ||||
| 		args := c.Args() | ||||
| 		if args.Present() { | ||||
| 			return ShowCommandHelp(c, args.First()) | ||||
| 		} | ||||
|  | ||||
| 		_ = ShowAppHelp(c) | ||||
| 		return nil | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| var helpSubcommand = &Command{ | ||||
| 	Name:      "help", | ||||
| 	Aliases:   []string{"h"}, | ||||
| 	Usage:     "Shows a list of commands or help for one command", | ||||
| 	ArgsUsage: "[command]", | ||||
| 	Action: func(c *Context) error { | ||||
| 		args := c.Args() | ||||
| 		if args.Present() { | ||||
| 			return ShowCommandHelp(c, args.First()) | ||||
| 		} | ||||
|  | ||||
| 		return ShowSubcommandHelp(c) | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| // Prints help for the App or Command | ||||
| type helpPrinter func(w io.Writer, templ string, data interface{}) | ||||
|  | ||||
| // Prints help for the App or Command with custom template function. | ||||
| type helpPrinterCustom func(w io.Writer, templ string, data interface{}, customFunc map[string]interface{}) | ||||
|  | ||||
| // HelpPrinter is a function that writes the help output. If not set explicitly, | ||||
| // this calls HelpPrinterCustom using only the default template functions. | ||||
| // | ||||
| // If custom logic for printing help is required, this function can be | ||||
| // overridden. If the ExtraInfo field is defined on an App, this function | ||||
| // should not be modified, as HelpPrinterCustom will be used directly in order | ||||
| // to capture the extra information. | ||||
| var HelpPrinter helpPrinter = printHelp | ||||
|  | ||||
| // HelpPrinterCustom is a function that writes the help output. It is used as | ||||
| // the default implementation of HelpPrinter, and may be called directly if | ||||
| // the ExtraInfo field is set on an App. | ||||
| var HelpPrinterCustom helpPrinterCustom = printHelpCustom | ||||
|  | ||||
| // VersionPrinter prints the version for the App | ||||
| 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) | ||||
| 	os.Exit(exitCode) | ||||
| } | ||||
|  | ||||
| // ShowAppHelp is an action that displays the help. | ||||
| func ShowAppHelp(c *Context) error { | ||||
| 	template := c.App.CustomAppHelpTemplate | ||||
| 	if template == "" { | ||||
| 		template = AppHelpTemplate | ||||
| 	} | ||||
|  | ||||
| 	if c.App.ExtraInfo == nil { | ||||
| 		HelpPrinter(c.App.Writer, template, c.App) | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	customAppData := func() map[string]interface{} { | ||||
| 		return map[string]interface{}{ | ||||
| 			"ExtraInfo": c.App.ExtraInfo, | ||||
| 		} | ||||
| 	} | ||||
| 	HelpPrinterCustom(c.App.Writer, template, c.App, customAppData()) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // DefaultAppComplete prints the list of subcommands as the default app completion method | ||||
| func DefaultAppComplete(c *Context) { | ||||
| 	DefaultCompleteWithFlags(nil)(c) | ||||
| } | ||||
|  | ||||
| func printCommandSuggestions(commands []*Command, writer io.Writer) { | ||||
| 	for _, command := range commands { | ||||
| 		if command.Hidden { | ||||
| 			continue | ||||
| 		} | ||||
| 		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 flag.Names() { | ||||
| 			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(name) { | ||||
| 				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) | ||||
| 	os.Exit(code) | ||||
| } | ||||
|  | ||||
| // ShowCommandHelp prints help for the given command | ||||
| func ShowCommandHelp(ctx *Context, command string) error { | ||||
| 	// show the subcommand help for a command with subcommands | ||||
| 	if command == "" { | ||||
| 		HelpPrinter(ctx.App.Writer, SubcommandHelpTemplate, ctx.App) | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	for _, c := range ctx.App.Commands { | ||||
| 		if c.HasName(command) { | ||||
| 			templ := c.CustomHelpTemplate | ||||
| 			if templ == "" { | ||||
| 				templ = CommandHelpTemplate | ||||
| 			} | ||||
|  | ||||
| 			HelpPrinter(ctx.App.Writer, templ, c) | ||||
|  | ||||
| 			return nil | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if ctx.App.CommandNotFound == nil { | ||||
| 		return Exit(fmt.Sprintf("No help topic for '%v'", command), 3) | ||||
| 	} | ||||
|  | ||||
| 	ctx.App.CommandNotFound(ctx, command) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // ShowSubcommandHelp prints help for the given subcommand | ||||
| func ShowSubcommandHelp(c *Context) error { | ||||
| 	if c == nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	if c.Command != nil { | ||||
| 		return ShowCommandHelp(c, c.Command.Name) | ||||
| 	} | ||||
|  | ||||
| 	return ShowCommandHelp(c, "") | ||||
| } | ||||
|  | ||||
| // ShowVersion prints the version number of the App | ||||
| func ShowVersion(c *Context) { | ||||
| 	VersionPrinter(c) | ||||
| } | ||||
|  | ||||
| func printVersion(c *Context) { | ||||
| 	_, _ = 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 | ||||
| func ShowCompletions(c *Context) { | ||||
| 	a := c.App | ||||
| 	if a != nil && a.BashComplete != nil { | ||||
| 		a.BashComplete(c) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // ShowCommandCompletions prints the custom completions for a given command | ||||
| func ShowCommandCompletions(ctx *Context, command string) { | ||||
| 	c := ctx.App.Command(command) | ||||
| 	if c != nil { | ||||
| 		if c.BashComplete != nil { | ||||
| 			c.BashComplete(ctx) | ||||
| 		} else { | ||||
| 			DefaultCompleteWithFlags(c)(ctx) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| } | ||||
|  | ||||
| // printHelpCustom is the default implementation of HelpPrinterCustom. | ||||
| // | ||||
| // The customFuncs map will be combined with a default template.FuncMap to | ||||
| // allow using arbitrary functions in template rendering. | ||||
| func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs map[string]interface{}) { | ||||
| 	funcMap := template.FuncMap{ | ||||
| 		"join": strings.Join, | ||||
| 	} | ||||
| 	for key, value := range customFuncs { | ||||
| 		funcMap[key] = value | ||||
| 	} | ||||
|  | ||||
| 	w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0) | ||||
| 	t := template.Must(template.New("help").Funcs(funcMap).Parse(templ)) | ||||
|  | ||||
| 	err := t.Execute(w, data) | ||||
| 	if err != nil { | ||||
| 		// 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) | ||||
| 		} | ||||
| 		return | ||||
| 	} | ||||
| 	_ = w.Flush() | ||||
| } | ||||
|  | ||||
| func printHelp(out io.Writer, templ string, data interface{}) { | ||||
| 	HelpPrinterCustom(out, templ, data, nil) | ||||
| } | ||||
|  | ||||
| func checkVersion(c *Context) bool { | ||||
| 	found := false | ||||
| 	for _, name := range VersionFlag.Names() { | ||||
| 		if c.Bool(name) { | ||||
| 			found = true | ||||
| 		} | ||||
| 	} | ||||
| 	return found | ||||
| } | ||||
|  | ||||
| func checkHelp(c *Context) bool { | ||||
| 	found := false | ||||
| 	for _, name := range HelpFlag.Names() { | ||||
| 		if c.Bool(name) { | ||||
| 			found = true | ||||
| 		} | ||||
| 	} | ||||
| 	return found | ||||
| } | ||||
|  | ||||
| func checkCommandHelp(c *Context, name string) bool { | ||||
| 	if c.Bool("h") || c.Bool("help") { | ||||
| 		_ = ShowCommandHelp(c, name) | ||||
| 		return true | ||||
| 	} | ||||
|  | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| func checkSubcommandHelp(c *Context) bool { | ||||
| 	if c.Bool("h") || c.Bool("help") { | ||||
| 		_ = ShowSubcommandHelp(c) | ||||
| 		return true | ||||
| 	} | ||||
|  | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) { | ||||
| 	if !a.EnableBashCompletion { | ||||
| 		return false, arguments | ||||
| 	} | ||||
|  | ||||
| 	pos := len(arguments) - 1 | ||||
| 	lastArg := arguments[pos] | ||||
|  | ||||
| 	if lastArg != "--generate-bash-completion" { | ||||
| 		return false, arguments | ||||
| 	} | ||||
|  | ||||
| 	return true, arguments[:pos] | ||||
| } | ||||
|  | ||||
| func checkCompletions(c *Context) bool { | ||||
| 	if !c.shellComplete { | ||||
| 		return false | ||||
| 	} | ||||
|  | ||||
| 	if args := c.Args(); args.Present() { | ||||
| 		name := args.First() | ||||
| 		if cmd := c.App.Command(name); cmd != nil { | ||||
| 			// let the command handle the completion | ||||
| 			return false | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	ShowCompletions(c) | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| func checkCommandCompletions(c *Context, name string) bool { | ||||
| 	if !c.shellComplete { | ||||
| 		return false | ||||
| 	} | ||||
|  | ||||
| 	ShowCommandCompletions(c, name) | ||||
| 	return true | ||||
| } | ||||
							
								
								
									
										94
									
								
								vendor/github.com/urfave/cli/v2/parse.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								vendor/github.com/urfave/cli/v2/parse.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,94 @@ | ||||
| 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. | ||||
| // Pass `shellComplete` to continue parsing options on failure during shell | ||||
| // completion when, the user-supplied options may be incomplete. | ||||
| func parseIter(set *flag.FlagSet, ip iterativeParser, args []string, shellComplete bool) error { | ||||
| 	for { | ||||
| 		err := set.Parse(args) | ||||
| 		if !ip.useShortOptionHandling() || err == nil { | ||||
| 			if shellComplete { | ||||
| 				return nil | ||||
| 			} | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		errStr := err.Error() | ||||
| 		trimmed := strings.TrimPrefix(errStr, "flag provided but not defined: -") | ||||
| 		if errStr == trimmed { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		// regenerate the initial args with the split short opts | ||||
| 		argsWereSplit := false | ||||
| 		for i, arg := range args { | ||||
| 			// skip args that are not part of the error message | ||||
| 			if name := strings.TrimLeft(arg, "-"); name != trimmed { | ||||
| 				continue | ||||
| 			} | ||||
|  | ||||
| 			// if we can't split, the error was accurate | ||||
| 			shortOpts := splitShortOptions(set, arg) | ||||
| 			if len(shortOpts) == 1 { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			// swap current argument with the split version | ||||
| 			args = append(args[:i], append(shortOpts, args[i+1:]...)...) | ||||
| 			argsWereSplit = true | ||||
| 			break | ||||
| 		} | ||||
|  | ||||
| 		// This should be an impossible to reach code path, but in case the arg | ||||
| 		// splitting failed to happen, this will prevent infinite loops | ||||
| 		if !argsWereSplit { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		// Since custom parsing failed, replace the flag set before retrying | ||||
| 		newSet, err := ip.newFlagSet() | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		*set = *newSet | ||||
| 	} | ||||
| } | ||||
|  | ||||
| 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/v2/sort.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								vendor/github.com/urfave/cli/v2/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 | ||||
| } | ||||
							
								
								
									
										119
									
								
								vendor/github.com/urfave/cli/v2/template.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								vendor/github.com/urfave/cli/v2/template.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,119 @@ | ||||
| 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){{ if .App.Description }} {{ .App.Description }}{{ end }} | ||||
| {{ range $a := .App.Authors }} | ||||
| % {{ $a }}{{ end }} | ||||
|  | ||||
| # 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