diff --git a/go.mod b/go.mod index d36795a..7bc0930 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/fatih/color v1.13.0 github.com/pkg/errors v0.9.1 - github.com/urfave/cli/v2 v2.23.5 + github.com/urfave/cli/v2 v2.26.0 ) require ( diff --git a/go.sum b/go.sum index a81622d..a6f02a9 100644 --- a/go.sum +++ b/go.sum @@ -89,6 +89,8 @@ github.com/urfave/cli/v2 v2.20.3 h1:lOgGidH/N5loaigd9HjFsOIhXSTrzl7tBpHswZ428w4= github.com/urfave/cli/v2 v2.20.3/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= github.com/urfave/cli/v2 v2.23.5 h1:xbrU7tAYviSpqeR3X4nEFWUdB/uDZ6DE+HxmRU7Xtyw= github.com/urfave/cli/v2 v2.23.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/urfave/cli/v2 v2.26.0 h1:3f3AMg3HpThFNT4I++TKOejZO8yU55t3JnnSr4S4QEI= +github.com/urfave/cli/v2 v2.26.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/vendor/github.com/urfave/cli/v2/.gitignore b/vendor/github.com/urfave/cli/v2/.gitignore index d7d26b1..1ef91a6 100644 --- a/vendor/github.com/urfave/cli/v2/.gitignore +++ b/vendor/github.com/urfave/cli/v2/.gitignore @@ -4,6 +4,7 @@ .*envrc .envrc .idea +# goimports is installed here if not available /.local/ /site/ coverage.txt diff --git a/vendor/github.com/urfave/cli/v2/README.md b/vendor/github.com/urfave/cli/v2/README.md index eaed356..9080aee 100644 --- a/vendor/github.com/urfave/cli/v2/README.md +++ b/vendor/github.com/urfave/cli/v2/README.md @@ -1,9 +1,9 @@ # cli -[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://pkg.go.dev/github.com/urfave/cli/v2) -[![codebeat](https://codebeat.co/badges/0a8f30aa-f975-404b-b878-5fab3ae1cc5f)](https://codebeat.co/projects/github-com-urfave-cli) -[![Go Report Card](https://goreportcard.com/badge/urfave/cli)](https://goreportcard.com/report/urfave/cli) -[![codecov](https://codecov.io/gh/urfave/cli/branch/main/graph/badge.svg)](https://codecov.io/gh/urfave/cli) +[![Run Tests](https://github.com/urfave/cli/actions/workflows/cli.yml/badge.svg?branch=v2-maint)](https://github.com/urfave/cli/actions/workflows/cli.yml) +[![Go Reference](https://pkg.go.dev/badge/github.com/urfave/cli/v2.svg)](https://pkg.go.dev/github.com/urfave/cli/v2) +[![Go Report Card](https://goreportcard.com/badge/github.com/urfave/cli/v2)](https://goreportcard.com/report/github.com/urfave/cli/v2) +[![codecov](https://codecov.io/gh/urfave/cli/branch/v2-maint/graph/badge.svg?token=t9YGWLh05g)](https://app.codecov.io/gh/urfave/cli/tree/v2-maint) 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 diff --git a/vendor/github.com/urfave/cli/v2/app.go b/vendor/github.com/urfave/cli/v2/app.go index e7f79c5..f69a193 100644 --- a/vendor/github.com/urfave/cli/v2/app.go +++ b/vendor/github.com/urfave/cli/v2/app.go @@ -107,6 +107,8 @@ type App struct { CustomAppHelpTemplate string // SliceFlagSeparator is used to customize the separator for SliceFlag, the default is "," SliceFlagSeparator string + // DisableSliceFlagSeparator is used to disable SliceFlagSeparator, the default is false + DisableSliceFlagSeparator 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 @@ -119,7 +121,8 @@ type App struct { // Treat all flags as normal arguments if true SkipFlagParsing bool - didSetup bool + didSetup bool + separator separatorSpec rootCommand *Command } @@ -214,6 +217,16 @@ func (a *App) Setup() { }) } + if len(a.SliceFlagSeparator) != 0 { + a.separator.customized = true + a.separator.sep = a.SliceFlagSeparator + } + + if a.DisableSliceFlagSeparator { + a.separator.customized = true + a.separator.disabled = true + } + var newCommands []*Command for _, c := range a.Commands { @@ -221,8 +234,8 @@ func (a *App) Setup() { if c.HelpName != "" { cname = c.HelpName } + c.separator = a.separator c.HelpName = fmt.Sprintf("%s %s", a.HelpName, cname) - c.flagCategories = newFlagCategoriesFromFlags(c.Flags) newCommands = append(newCommands, c) } @@ -248,22 +261,11 @@ func (a *App) Setup() { } sort.Sort(a.categories.(*commandCategories)) - a.flagCategories = newFlagCategories() - for _, fl := range a.Flags { - if cf, ok := fl.(CategorizableFlag); ok { - if cf.GetCategory() != "" { - a.flagCategories.AddFlag(cf.GetCategory(), cf) - } - } - } + a.flagCategories = newFlagCategoriesFromFlags(a.Flags) if a.Metadata == nil { a.Metadata = make(map[string]interface{}) } - - if len(a.SliceFlagSeparator) != 0 { - defaultSliceFlagSeparator = a.SliceFlagSeparator - } } func (a *App) newRootCommand() *Command { @@ -289,11 +291,12 @@ func (a *App) newRootCommand() *Command { categories: a.categories, SkipFlagParsing: a.SkipFlagParsing, isRoot: true, + separator: a.separator, } } func (a *App) newFlagSet() (*flag.FlagSet, error) { - return flagSet(a.Name, a.Flags) + return flagSet(a.Name, a.Flags, a.separator) } func (a *App) useShortOptionHandling() bool { @@ -326,14 +329,24 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) { a.rootCommand = a.newRootCommand() cCtx.Command = a.rootCommand + if err := checkDuplicatedCmds(a.rootCommand); err != nil { + return err + } return a.rootCommand.Run(cCtx, arguments...) } -// This is a stub function to keep public API unchanged from old code -// -// Deprecated: use App.Run or App.RunContext +// RunAsSubcommand is for legacy/compatibility purposes only. New code should only +// use App.RunContext. This function is slated to be removed in v3. func (a *App) RunAsSubcommand(ctx *Context) (err error) { - return a.RunContext(ctx.Context, ctx.Args().Slice()) + a.Setup() + + cCtx := NewContext(a, nil, ctx) + cCtx.shellComplete = ctx.shellComplete + + a.rootCommand = a.newRootCommand() + cCtx.Command = a.rootCommand + + return a.rootCommand.Run(cCtx, ctx.Args().Slice()...) } func (a *App) suggestFlagFromError(err error, command string) (string, error) { @@ -445,30 +458,6 @@ func (a *App) handleExitCoder(cCtx *Context, err error) { } } -func (a *App) commandNames() []string { - var cmdNames []string - - for _, cmd := range a.Commands { - cmdNames = append(cmdNames, cmd.Names()...) - } - - return cmdNames -} - -func (a *App) validCommandName(checkCmdName string) bool { - valid := false - allCommandNames := a.commandNames() - - for _, cmdName := range allCommandNames { - if checkCmdName == cmdName { - valid = true - break - } - } - - return valid -} - func (a *App) argsWithDefaultCommand(oldArgs Args) Args { if a.DefaultCommand != "" { rawArgs := append([]string{a.DefaultCommand}, oldArgs.Slice()...) diff --git a/vendor/github.com/urfave/cli/v2/category.go b/vendor/github.com/urfave/cli/v2/category.go index 7aca0c7..b1847ec 100644 --- a/vendor/github.com/urfave/cli/v2/category.go +++ b/vendor/github.com/urfave/cli/v2/category.go @@ -100,10 +100,23 @@ func newFlagCategories() FlagCategories { func newFlagCategoriesFromFlags(fs []Flag) FlagCategories { fc := newFlagCategories() + + var categorized bool for _, fl := range fs { if cf, ok := fl.(CategorizableFlag); ok { - if cf.GetCategory() != "" { - fc.AddFlag(cf.GetCategory(), cf) + if cat := cf.GetCategory(); cat != "" { + fc.AddFlag(cat, cf) + categorized = true + } + } + } + + if categorized { + for _, fl := range fs { + if cf, ok := fl.(CategorizableFlag); ok { + if cf.GetCategory() == "" { + fc.AddFlag("", fl) + } } } } diff --git a/vendor/github.com/urfave/cli/v2/command.go b/vendor/github.com/urfave/cli/v2/command.go index c5939d4..c318da9 100644 --- a/vendor/github.com/urfave/cli/v2/command.go +++ b/vendor/github.com/urfave/cli/v2/command.go @@ -69,6 +69,8 @@ type Command struct { // if this is a root "special" command isRoot bool + + separator separatorSpec } type Commands []*Command @@ -133,26 +135,30 @@ func (c *Command) setup(ctx *Context) { if scmd.HelpName == "" { scmd.HelpName = fmt.Sprintf("%s %s", c.HelpName, scmd.Name) } + scmd.separator = c.separator newCmds = append(newCmds, scmd) } c.Subcommands = newCmds + + if c.BashComplete == nil { + c.BashComplete = DefaultCompleteWithFlags(c) + } } func (c *Command) Run(cCtx *Context, arguments ...string) (err error) { if !c.isRoot { c.setup(cCtx) + if err := checkDuplicatedCmds(c); err != nil { + return err + } } a := args(arguments) set, err := c.parseFlags(&a, cCtx.shellComplete) cCtx.flagSet = set - if c.isRoot { - if checkCompletions(cCtx) { - return nil - } - } else if checkCommandCompletions(cCtx, c.Name) { + if checkCompletions(cCtx) { return nil } @@ -203,7 +209,7 @@ func (c *Command) Run(cCtx *Context, arguments ...string) (err error) { cerr := cCtx.checkRequiredFlags(c.Flags) if cerr != nil { - _ = ShowSubcommandHelp(cCtx) + _ = helpCommand.Action(cCtx) return cerr } @@ -275,7 +281,7 @@ func (c *Command) Run(cCtx *Context, arguments ...string) (err error) { } func (c *Command) newFlagSet() (*flag.FlagSet, error) { - return flagSet(c.Name, c.Flags) + return flagSet(c.Name, c.Flags, c.separator) } func (c *Command) useShortOptionHandling() bool { @@ -401,3 +407,16 @@ func hasCommand(commands []*Command, command *Command) bool { return false } + +func checkDuplicatedCmds(parent *Command) error { + seen := make(map[string]struct{}) + for _, c := range parent.Subcommands { + for _, name := range c.Names() { + if _, exists := seen[name]; exists { + return fmt.Errorf("parent command [%s] has duplicated subcommand name or alias: %s", parent.Name, name) + } + seen[name] = struct{}{} + } + } + return nil +} diff --git a/vendor/github.com/urfave/cli/v2/context.go b/vendor/github.com/urfave/cli/v2/context.go index dbf50e4..a45c120 100644 --- a/vendor/github.com/urfave/cli/v2/context.go +++ b/vendor/github.com/urfave/cli/v2/context.go @@ -56,6 +56,7 @@ func (cCtx *Context) Set(name, value string) error { // IsSet determines if the flag was actually set func (cCtx *Context) IsSet(name string) bool { + if fs := cCtx.lookupFlagSet(name); fs != nil { isSet := false fs.Visit(func(f *flag.Flag) { @@ -72,7 +73,23 @@ func (cCtx *Context) IsSet(name string) bool { return false } - return f.IsSet() + if f.IsSet() { + return true + } + + // now redo flagset search on aliases + aliases := f.Names() + fs.Visit(func(f *flag.Flag) { + for _, alias := range aliases { + if f.Name == alias { + isSet = true + } + } + }) + + if isSet { + return true + } } return false @@ -204,9 +221,10 @@ func (cCtx *Context) checkRequiredFlags(flags []Flag) requiredFlagsErr { var flagPresent bool var flagName string - for _, key := range f.Names() { - flagName = key + flagNames := f.Names() + flagName = flagNames[0] + for _, key := range flagNames { if cCtx.IsSet(strings.TrimSpace(key)) { flagPresent = true } diff --git a/vendor/github.com/urfave/cli/v2/docs.go b/vendor/github.com/urfave/cli/v2/docs.go index 8b1c9c8..6cd0624 100644 --- a/vendor/github.com/urfave/cli/v2/docs.go +++ b/vendor/github.com/urfave/cli/v2/docs.go @@ -153,9 +153,14 @@ func prepareFlags( // flagDetails returns a string containing the flags metadata func flagDetails(flag DocGenerationFlag) string { description := flag.GetUsage() - value := flag.GetValue() - if value != "" { - description += " (default: " + value + ")" + if flag.TakesValue() { + defaultText := flag.GetDefaultText() + if defaultText == "" { + defaultText = flag.GetValue() + } + if defaultText != "" { + description += " (default: " + defaultText + ")" + } } return ": " + description } diff --git a/vendor/github.com/urfave/cli/v2/flag-spec.yaml b/vendor/github.com/urfave/cli/v2/flag-spec.yaml index 76480ba..03d82e7 100644 --- a/vendor/github.com/urfave/cli/v2/flag-spec.yaml +++ b/vendor/github.com/urfave/cli/v2/flag-spec.yaml @@ -7,6 +7,8 @@ flag_types: - name: Count type: int pointer: true + - name: DisableDefaultText + type: bool - name: Action type: "func(*Context, bool) error" float64: @@ -18,6 +20,8 @@ flag_types: skip_interfaces: - fmt.Stringer struct_fields: + - name: separator + type: separatorSpec - name: Action type: "func(*Context, []float64) error" int: @@ -31,6 +35,8 @@ flag_types: skip_interfaces: - fmt.Stringer struct_fields: + - name: separator + type: separatorSpec - name: Action type: "func(*Context, []int) error" int64: @@ -44,6 +50,8 @@ flag_types: skip_interfaces: - fmt.Stringer struct_fields: + - name: separator + type: separatorSpec - name: Action type: "func(*Context, []int64) error" uint: @@ -57,6 +65,8 @@ flag_types: skip_interfaces: - fmt.Stringer struct_fields: + - name: separator + type: separatorSpec - name: Action type: "func(*Context, []uint) error" uint64: @@ -70,6 +80,8 @@ flag_types: skip_interfaces: - fmt.Stringer struct_fields: + - name: separator + type: separatorSpec - name: Action type: "func(*Context, []uint64) error" string: @@ -83,10 +95,14 @@ flag_types: skip_interfaces: - fmt.Stringer struct_fields: + - name: separator + type: separatorSpec - name: TakesFile type: bool - name: Action type: "func(*Context, []string) error" + - name: KeepSpace + type: bool time.Duration: struct_fields: - name: Action diff --git a/vendor/github.com/urfave/cli/v2/flag.go b/vendor/github.com/urfave/cli/v2/flag.go index b66a75d..4d04de3 100644 --- a/vendor/github.com/urfave/cli/v2/flag.go +++ b/vendor/github.com/urfave/cli/v2/flag.go @@ -4,7 +4,7 @@ import ( "errors" "flag" "fmt" - "io/ioutil" + "io" "os" "regexp" "runtime" @@ -15,7 +15,10 @@ import ( const defaultPlaceholder = "value" -var defaultSliceFlagSeparator = "," +const ( + defaultSliceFlagSeparator = "," + disableSliceFlagSeparator = false +) var ( slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano()) @@ -31,18 +34,20 @@ var BashCompletionFlag Flag = &BoolFlag{ // VersionFlag prints the version for the application var VersionFlag Flag = &BoolFlag{ - Name: "version", - Aliases: []string{"v"}, - Usage: "print the version", + Name: "version", + Aliases: []string{"v"}, + Usage: "print the version", + DisableDefaultText: true, } // HelpFlag prints the help for all commands and subcommands. // Set to nil to disable the flag. The subcommand // will still be added unless HideHelp or HideHelpCommand is set to true. var HelpFlag Flag = &BoolFlag{ - Name: "help", - Aliases: []string{"h"}, - Usage: "show help", + Name: "help", + Aliases: []string{"h"}, + Usage: "show help", + DisableDefaultText: true, } // FlagStringer converts a flag definition to a string. This is used by help @@ -162,15 +167,18 @@ type Countable interface { Count() int } -func flagSet(name string, flags []Flag) (*flag.FlagSet, error) { +func flagSet(name string, flags []Flag, spec separatorSpec) (*flag.FlagSet, error) { set := flag.NewFlagSet(name, flag.ContinueOnError) for _, f := range flags { + if c, ok := f.(customizedSeparator); ok { + c.WithSeparatorSpec(spec) + } if err := f.Apply(set); err != nil { return nil, err } } - set.SetOutput(ioutil.Discard) + set.SetOutput(io.Discard) return set, nil } @@ -334,8 +342,13 @@ func stringifyFlag(f Flag) string { defaultValueString := "" - if s := df.GetDefaultText(); s != "" { - defaultValueString = fmt.Sprintf(formatDefault("%s"), s) + // set default text for all flags except bool flags + // for bool flags display default text if DisableDefaultText is not + // set + if bf, ok := f.(*BoolFlag); !ok || !bf.DisableDefaultText { + if s := df.GetDefaultText(); s != "" { + defaultValueString = fmt.Sprintf(formatDefault("%s"), s) + } } usageWithDefault := strings.TrimSpace(usage + defaultValueString) @@ -371,7 +384,7 @@ func flagFromEnvOrFile(envVars []string, filePath string) (value string, fromWhe } for _, fileVar := range strings.Split(filePath, ",") { if fileVar != "" { - if data, err := ioutil.ReadFile(fileVar); err == nil { + if data, err := os.ReadFile(fileVar); err == nil { return string(data), fmt.Sprintf("file %q", filePath), true } } @@ -379,6 +392,28 @@ func flagFromEnvOrFile(envVars []string, filePath string) (value string, fromWhe return "", "", false } -func flagSplitMultiValues(val string) []string { - return strings.Split(val, defaultSliceFlagSeparator) +type customizedSeparator interface { + WithSeparatorSpec(separatorSpec) +} + +type separatorSpec struct { + sep string + disabled bool + customized bool +} + +func (s separatorSpec) flagSplitMultiValues(val string) []string { + var ( + disabled bool = s.disabled + sep string = s.sep + ) + if !s.customized { + disabled = disableSliceFlagSeparator + sep = defaultSliceFlagSeparator + } + if disabled { + return []string{val} + } + + return strings.Split(val, sep) } diff --git a/vendor/github.com/urfave/cli/v2/flag_bool.go b/vendor/github.com/urfave/cli/v2/flag_bool.go index f64d1cd..01862ea 100644 --- a/vendor/github.com/urfave/cli/v2/flag_bool.go +++ b/vendor/github.com/urfave/cli/v2/flag_bool.go @@ -52,7 +52,7 @@ func (b *boolValue) String() string { func (b *boolValue) IsBoolFlag() bool { return true } func (b *boolValue) Count() int { - if b.count != nil { + if b.count != nil && *b.count > 0 { return *b.count } return 0 @@ -84,7 +84,10 @@ func (f *BoolFlag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - return fmt.Sprintf("%v", f.defaultValue) + if f.defaultValueSet { + return fmt.Sprintf("%v", f.defaultValue) + } + return fmt.Sprintf("%v", f.Value) } // GetEnvVars returns the env vars for this flag @@ -105,6 +108,7 @@ func (f *BoolFlag) RunAction(c *Context) error { func (f *BoolFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it f.defaultValue = f.Value + f.defaultValueSet = true if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if val != "" { @@ -130,6 +134,11 @@ func (f *BoolFlag) Apply(set *flag.FlagSet) error { if count == nil { count = new(int) } + + // since count will be incremented for each alias as well + // subtract number of aliases from overall count + *count -= len(f.Aliases) + if dest == nil { dest = new(bool) } diff --git a/vendor/github.com/urfave/cli/v2/flag_duration.go b/vendor/github.com/urfave/cli/v2/flag_duration.go index eac4cb8..e600cc3 100644 --- a/vendor/github.com/urfave/cli/v2/flag_duration.go +++ b/vendor/github.com/urfave/cli/v2/flag_duration.go @@ -32,7 +32,10 @@ func (f *DurationFlag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - return f.defaultValue.String() + if f.defaultValueSet { + return f.defaultValue.String() + } + return f.Value.String() } // GetEnvVars returns the env vars for this flag @@ -44,6 +47,7 @@ func (f *DurationFlag) GetEnvVars() []string { func (f *DurationFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it f.defaultValue = f.Value + f.defaultValueSet = true if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if val != "" { diff --git a/vendor/github.com/urfave/cli/v2/flag_float64.go b/vendor/github.com/urfave/cli/v2/flag_float64.go index bce26c1..6a4de5c 100644 --- a/vendor/github.com/urfave/cli/v2/flag_float64.go +++ b/vendor/github.com/urfave/cli/v2/flag_float64.go @@ -32,7 +32,10 @@ func (f *Float64Flag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - return f.GetValue() + if f.defaultValueSet { + return fmt.Sprintf("%v", f.defaultValue) + } + return fmt.Sprintf("%v", f.Value) } // GetEnvVars returns the env vars for this flag @@ -42,6 +45,9 @@ func (f *Float64Flag) GetEnvVars() []string { // Apply populates the flag given the flag set and environment func (f *Float64Flag) Apply(set *flag.FlagSet) error { + f.defaultValue = f.Value + f.defaultValueSet = true + if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if val != "" { valFloat, err := strconv.ParseFloat(val, 64) diff --git a/vendor/github.com/urfave/cli/v2/flag_float64_slice.go b/vendor/github.com/urfave/cli/v2/flag_float64_slice.go index 413aa50..0bc4612 100644 --- a/vendor/github.com/urfave/cli/v2/flag_float64_slice.go +++ b/vendor/github.com/urfave/cli/v2/flag_float64_slice.go @@ -11,6 +11,7 @@ import ( // Float64Slice wraps []float64 to satisfy flag.Value type Float64Slice struct { slice []float64 + separator separatorSpec hasBeenSet bool } @@ -29,6 +30,10 @@ func (f *Float64Slice) clone() *Float64Slice { return n } +func (f *Float64Slice) WithSeparatorSpec(spec separatorSpec) { + f.separator = spec +} + // 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 { @@ -43,7 +48,7 @@ func (f *Float64Slice) Set(value string) error { return nil } - for _, s := range flagSplitMultiValues(value) { + for _, s := range f.separator.flagSplitMultiValues(value) { tmp, err := strconv.ParseFloat(strings.TrimSpace(s), 64) if err != nil { return err @@ -148,11 +153,12 @@ func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error { setValue = f.Value.clone() default: setValue = new(Float64Slice) + setValue.WithSeparatorSpec(f.separator) } if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if val != "" { - for _, s := range flagSplitMultiValues(val) { + for _, s := range f.separator.flagSplitMultiValues(val) { if err := setValue.Set(strings.TrimSpace(s)); err != nil { return fmt.Errorf("could not parse %q as float64 slice value from %s for flag %s: %s", val, source, f.Name, err) } @@ -172,6 +178,10 @@ func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error { return nil } +func (f *Float64SliceFlag) WithSeparatorSpec(spec separatorSpec) { + f.separator = spec +} + // Get returns the flag’s value in the given Context. func (f *Float64SliceFlag) Get(ctx *Context) []float64 { return ctx.Float64Slice(f.Name) diff --git a/vendor/github.com/urfave/cli/v2/flag_generic.go b/vendor/github.com/urfave/cli/v2/flag_generic.go index 4f9ac0a..7528c93 100644 --- a/vendor/github.com/urfave/cli/v2/flag_generic.go +++ b/vendor/github.com/urfave/cli/v2/flag_generic.go @@ -53,9 +53,15 @@ func (f *GenericFlag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - if f.defaultValue != nil { - return f.defaultValue.String() + val := f.Value + if f.defaultValueSet { + val = f.defaultValue } + + if val != nil { + return val.String() + } + return "" } @@ -70,6 +76,7 @@ func (f *GenericFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it if f.Value != nil { f.defaultValue = &stringGeneric{value: f.Value.String()} + f.defaultValueSet = true } if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { @@ -117,13 +124,8 @@ func (cCtx *Context) Generic(name string) interface{} { } 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 + if f := set.Lookup(name); f != nil { + return f.Value } return nil } diff --git a/vendor/github.com/urfave/cli/v2/flag_int.go b/vendor/github.com/urfave/cli/v2/flag_int.go index d681270..750e7eb 100644 --- a/vendor/github.com/urfave/cli/v2/flag_int.go +++ b/vendor/github.com/urfave/cli/v2/flag_int.go @@ -32,7 +32,10 @@ func (f *IntFlag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - return fmt.Sprintf("%d", f.defaultValue) + if f.defaultValueSet { + return fmt.Sprintf("%d", f.defaultValue) + } + return fmt.Sprintf("%d", f.Value) } // GetEnvVars returns the env vars for this flag @@ -44,6 +47,7 @@ func (f *IntFlag) GetEnvVars() []string { func (f *IntFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it f.defaultValue = f.Value + f.defaultValueSet = true if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if val != "" { diff --git a/vendor/github.com/urfave/cli/v2/flag_int64.go b/vendor/github.com/urfave/cli/v2/flag_int64.go index 6f8c8d2..688c267 100644 --- a/vendor/github.com/urfave/cli/v2/flag_int64.go +++ b/vendor/github.com/urfave/cli/v2/flag_int64.go @@ -32,7 +32,10 @@ func (f *Int64Flag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - return fmt.Sprintf("%d", f.defaultValue) + if f.defaultValueSet { + return fmt.Sprintf("%d", f.defaultValue) + } + return fmt.Sprintf("%d", f.Value) } // GetEnvVars returns the env vars for this flag @@ -44,6 +47,7 @@ func (f *Int64Flag) GetEnvVars() []string { func (f *Int64Flag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it f.defaultValue = f.Value + f.defaultValueSet = true if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if val != "" { diff --git a/vendor/github.com/urfave/cli/v2/flag_int64_slice.go b/vendor/github.com/urfave/cli/v2/flag_int64_slice.go index c45c43d..d45c2dd 100644 --- a/vendor/github.com/urfave/cli/v2/flag_int64_slice.go +++ b/vendor/github.com/urfave/cli/v2/flag_int64_slice.go @@ -11,6 +11,7 @@ import ( // Int64Slice wraps []int64 to satisfy flag.Value type Int64Slice struct { slice []int64 + separator separatorSpec hasBeenSet bool } @@ -29,6 +30,10 @@ func (i *Int64Slice) clone() *Int64Slice { return n } +func (i *Int64Slice) WithSeparatorSpec(spec separatorSpec) { + i.separator = spec +} + // 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 { @@ -43,7 +48,7 @@ func (i *Int64Slice) Set(value string) error { return nil } - for _, s := range flagSplitMultiValues(value) { + for _, s := range i.separator.flagSplitMultiValues(value) { tmp, err := strconv.ParseInt(strings.TrimSpace(s), 0, 64) if err != nil { return err @@ -149,10 +154,11 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error { setValue = f.Value.clone() default: setValue = new(Int64Slice) + setValue.WithSeparatorSpec(f.separator) } if val, source, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok && val != "" { - for _, s := range flagSplitMultiValues(val) { + for _, s := range f.separator.flagSplitMultiValues(val) { if err := setValue.Set(strings.TrimSpace(s)); err != nil { return fmt.Errorf("could not parse %q as int64 slice value from %s for flag %s: %s", val, source, f.Name, err) } @@ -171,6 +177,10 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error { return nil } +func (f *Int64SliceFlag) WithSeparatorSpec(spec separatorSpec) { + f.separator = spec +} + // Get returns the flag’s value in the given Context. func (f *Int64SliceFlag) Get(ctx *Context) []int64 { return ctx.Int64Slice(f.Name) diff --git a/vendor/github.com/urfave/cli/v2/flag_int_slice.go b/vendor/github.com/urfave/cli/v2/flag_int_slice.go index d4006e5..da9c09b 100644 --- a/vendor/github.com/urfave/cli/v2/flag_int_slice.go +++ b/vendor/github.com/urfave/cli/v2/flag_int_slice.go @@ -11,6 +11,7 @@ import ( // IntSlice wraps []int to satisfy flag.Value type IntSlice struct { slice []int + separator separatorSpec hasBeenSet bool } @@ -40,6 +41,10 @@ func (i *IntSlice) SetInt(value int) { i.slice = append(i.slice, value) } +func (i *IntSlice) WithSeparatorSpec(spec separatorSpec) { + i.separator = spec +} + // 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 { @@ -54,7 +59,7 @@ func (i *IntSlice) Set(value string) error { return nil } - for _, s := range flagSplitMultiValues(value) { + for _, s := range i.separator.flagSplitMultiValues(value) { tmp, err := strconv.ParseInt(strings.TrimSpace(s), 0, 64) if err != nil { return err @@ -160,10 +165,11 @@ func (f *IntSliceFlag) Apply(set *flag.FlagSet) error { setValue = f.Value.clone() default: setValue = new(IntSlice) + setValue.WithSeparatorSpec(f.separator) } if val, source, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok && val != "" { - for _, s := range flagSplitMultiValues(val) { + for _, s := range f.separator.flagSplitMultiValues(val) { if err := setValue.Set(strings.TrimSpace(s)); err != nil { return fmt.Errorf("could not parse %q as int slice value from %s for flag %s: %s", val, source, f.Name, err) } @@ -182,6 +188,10 @@ func (f *IntSliceFlag) Apply(set *flag.FlagSet) error { return nil } +func (f *IntSliceFlag) WithSeparatorSpec(spec separatorSpec) { + f.separator = spec +} + // Get returns the flag’s value in the given Context. func (f *IntSliceFlag) Get(ctx *Context) []int { return ctx.IntSlice(f.Name) diff --git a/vendor/github.com/urfave/cli/v2/flag_path.go b/vendor/github.com/urfave/cli/v2/flag_path.go index 6434d32..76cb352 100644 --- a/vendor/github.com/urfave/cli/v2/flag_path.go +++ b/vendor/github.com/urfave/cli/v2/flag_path.go @@ -33,10 +33,14 @@ func (f *PathFlag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - if f.defaultValue == "" { - return f.defaultValue + val := f.Value + if f.defaultValueSet { + val = f.defaultValue } - return fmt.Sprintf("%q", f.defaultValue) + if val == "" { + return val + } + return fmt.Sprintf("%q", val) } // GetEnvVars returns the env vars for this flag @@ -48,6 +52,7 @@ func (f *PathFlag) GetEnvVars() []string { func (f *PathFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it f.defaultValue = f.Value + f.defaultValueSet = true if val, _, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { f.Value = val @@ -90,13 +95,8 @@ func (cCtx *Context) Path(name string) string { } 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 + if f := set.Lookup(name); f != nil { + return f.Value.String() } return "" } diff --git a/vendor/github.com/urfave/cli/v2/flag_string.go b/vendor/github.com/urfave/cli/v2/flag_string.go index 3050086..0f73e06 100644 --- a/vendor/github.com/urfave/cli/v2/flag_string.go +++ b/vendor/github.com/urfave/cli/v2/flag_string.go @@ -31,10 +31,15 @@ func (f *StringFlag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - if f.defaultValue == "" { - return f.defaultValue + val := f.Value + if f.defaultValueSet { + val = f.defaultValue } - return fmt.Sprintf("%q", f.defaultValue) + + if val == "" { + return val + } + return fmt.Sprintf("%q", val) } // GetEnvVars returns the env vars for this flag @@ -46,6 +51,7 @@ func (f *StringFlag) GetEnvVars() []string { func (f *StringFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it f.defaultValue = f.Value + f.defaultValueSet = true if val, _, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { f.Value = val @@ -87,10 +93,8 @@ func (cCtx *Context) String(name string) string { } func lookupString(name string, set *flag.FlagSet) string { - f := set.Lookup(name) - if f != nil { - parsed := f.Value.String() - return parsed + if f := set.Lookup(name); f != nil { + return f.Value.String() } return "" } diff --git a/vendor/github.com/urfave/cli/v2/flag_string_slice.go b/vendor/github.com/urfave/cli/v2/flag_string_slice.go index baca2a2..28f4798 100644 --- a/vendor/github.com/urfave/cli/v2/flag_string_slice.go +++ b/vendor/github.com/urfave/cli/v2/flag_string_slice.go @@ -11,7 +11,9 @@ import ( // StringSlice wraps a []string to satisfy flag.Value type StringSlice struct { slice []string + separator separatorSpec hasBeenSet bool + keepSpace bool } // NewStringSlice creates a *StringSlice with default values @@ -43,13 +45,20 @@ func (s *StringSlice) Set(value string) error { return nil } - for _, t := range flagSplitMultiValues(value) { - s.slice = append(s.slice, strings.TrimSpace(t)) + for _, t := range s.separator.flagSplitMultiValues(value) { + if !s.keepSpace { + t = strings.TrimSpace(t) + } + s.slice = append(s.slice, t) } return nil } +func (s *StringSlice) WithSeparatorSpec(spec separatorSpec) { + s.separator = spec +} + // String returns a readable representation of this value (for usage defaults) func (s *StringSlice) String() string { return fmt.Sprintf("%s", s.slice) @@ -141,11 +150,17 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error { setValue = f.Value.clone() default: setValue = new(StringSlice) + setValue.WithSeparatorSpec(f.separator) } + setValue.keepSpace = f.KeepSpace + if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { - for _, s := range flagSplitMultiValues(val) { - if err := setValue.Set(strings.TrimSpace(s)); err != nil { + for _, s := range f.separator.flagSplitMultiValues(val) { + if !f.KeepSpace { + s = strings.TrimSpace(s) + } + if err := setValue.Set(s); err != nil { return fmt.Errorf("could not parse %q as string value from %s for flag %s: %s", val, source, f.Name, err) } } @@ -163,6 +178,10 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error { return nil } +func (f *StringSliceFlag) WithSeparatorSpec(spec separatorSpec) { + f.separator = spec +} + // Get returns the flag’s value in the given Context. func (f *StringSliceFlag) Get(ctx *Context) []string { return ctx.StringSlice(f.Name) diff --git a/vendor/github.com/urfave/cli/v2/flag_timestamp.go b/vendor/github.com/urfave/cli/v2/flag_timestamp.go index fa0671f..b901230 100644 --- a/vendor/github.com/urfave/cli/v2/flag_timestamp.go +++ b/vendor/github.com/urfave/cli/v2/flag_timestamp.go @@ -120,8 +120,13 @@ func (f *TimestampFlag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - if f.defaultValue != nil && f.defaultValue.timestamp != nil { - return f.defaultValue.timestamp.String() + val := f.Value + if f.defaultValueSet { + val = f.defaultValue + } + + if val != nil && val.timestamp != nil { + return val.timestamp.String() } return "" @@ -144,11 +149,7 @@ func (f *TimestampFlag) Apply(set *flag.FlagSet) error { f.Value.SetLocation(f.Timezone) f.defaultValue = f.Value.clone() - - if f.Destination != nil { - f.Destination.SetLayout(f.Layout) - f.Destination.SetLocation(f.Timezone) - } + f.defaultValueSet = true if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if err := f.Value.Set(val); err != nil { @@ -157,6 +158,10 @@ func (f *TimestampFlag) Apply(set *flag.FlagSet) error { f.HasBeenSet = true } + if f.Destination != nil { + *f.Destination = *f.Value + } + for _, name := range f.Names() { if f.Destination != nil { set.Var(f.Destination, name, f.Usage) diff --git a/vendor/github.com/urfave/cli/v2/flag_uint.go b/vendor/github.com/urfave/cli/v2/flag_uint.go index d11aa0a..8d5b854 100644 --- a/vendor/github.com/urfave/cli/v2/flag_uint.go +++ b/vendor/github.com/urfave/cli/v2/flag_uint.go @@ -25,6 +25,7 @@ func (f *UintFlag) GetCategory() string { func (f *UintFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it f.defaultValue = f.Value + f.defaultValueSet = true if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if val != "" { @@ -69,7 +70,10 @@ func (f *UintFlag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - return fmt.Sprintf("%d", f.defaultValue) + if f.defaultValueSet { + return fmt.Sprintf("%d", f.defaultValue) + } + return fmt.Sprintf("%d", f.Value) } // GetEnvVars returns the env vars for this flag diff --git a/vendor/github.com/urfave/cli/v2/flag_uint64.go b/vendor/github.com/urfave/cli/v2/flag_uint64.go index ea73100..c356e53 100644 --- a/vendor/github.com/urfave/cli/v2/flag_uint64.go +++ b/vendor/github.com/urfave/cli/v2/flag_uint64.go @@ -25,6 +25,7 @@ func (f *Uint64Flag) GetCategory() string { func (f *Uint64Flag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it f.defaultValue = f.Value + f.defaultValueSet = true if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { if val != "" { @@ -69,7 +70,10 @@ func (f *Uint64Flag) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - return fmt.Sprintf("%d", f.defaultValue) + if f.defaultValueSet { + return fmt.Sprintf("%d", f.defaultValue) + } + return fmt.Sprintf("%d", f.Value) } // GetEnvVars returns the env vars for this flag diff --git a/vendor/github.com/urfave/cli/v2/flag_uint64_slice.go b/vendor/github.com/urfave/cli/v2/flag_uint64_slice.go index 61bb30b..e845dd5 100644 --- a/vendor/github.com/urfave/cli/v2/flag_uint64_slice.go +++ b/vendor/github.com/urfave/cli/v2/flag_uint64_slice.go @@ -11,6 +11,7 @@ import ( // Uint64Slice wraps []int64 to satisfy flag.Value type Uint64Slice struct { slice []uint64 + separator separatorSpec hasBeenSet bool } @@ -43,7 +44,7 @@ func (i *Uint64Slice) Set(value string) error { return nil } - for _, s := range flagSplitMultiValues(value) { + for _, s := range i.separator.flagSplitMultiValues(value) { tmp, err := strconv.ParseUint(strings.TrimSpace(s), 0, 64) if err != nil { return err @@ -55,6 +56,10 @@ func (i *Uint64Slice) Set(value string) error { return nil } +func (i *Uint64Slice) WithSeparatorSpec(spec separatorSpec) { + i.separator = spec +} + // String returns a readable representation of this value (for usage defaults) func (i *Uint64Slice) String() string { v := i.slice @@ -153,10 +158,11 @@ func (f *Uint64SliceFlag) Apply(set *flag.FlagSet) error { setValue = f.Value.clone() default: setValue = new(Uint64Slice) + setValue.WithSeparatorSpec(f.separator) } if val, source, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok && val != "" { - for _, s := range flagSplitMultiValues(val) { + for _, s := range f.separator.flagSplitMultiValues(val) { if err := setValue.Set(strings.TrimSpace(s)); err != nil { return fmt.Errorf("could not parse %q as uint64 slice value from %s for flag %s: %s", val, source, f.Name, err) } @@ -175,6 +181,10 @@ func (f *Uint64SliceFlag) Apply(set *flag.FlagSet) error { return nil } +func (f *Uint64SliceFlag) WithSeparatorSpec(spec separatorSpec) { + f.separator = spec +} + // Get returns the flag’s value in the given Context. func (f *Uint64SliceFlag) Get(ctx *Context) []uint64 { return ctx.Uint64Slice(f.Name) diff --git a/vendor/github.com/urfave/cli/v2/flag_uint_slice.go b/vendor/github.com/urfave/cli/v2/flag_uint_slice.go index 363aa65..d2aed48 100644 --- a/vendor/github.com/urfave/cli/v2/flag_uint_slice.go +++ b/vendor/github.com/urfave/cli/v2/flag_uint_slice.go @@ -11,6 +11,7 @@ import ( // UintSlice wraps []int to satisfy flag.Value type UintSlice struct { slice []uint + separator separatorSpec hasBeenSet bool } @@ -54,7 +55,7 @@ func (i *UintSlice) Set(value string) error { return nil } - for _, s := range flagSplitMultiValues(value) { + for _, s := range i.separator.flagSplitMultiValues(value) { tmp, err := strconv.ParseUint(strings.TrimSpace(s), 0, 32) if err != nil { return err @@ -66,6 +67,10 @@ func (i *UintSlice) Set(value string) error { return nil } +func (i *UintSlice) WithSeparatorSpec(spec separatorSpec) { + i.separator = spec +} + // String returns a readable representation of this value (for usage defaults) func (i *UintSlice) String() string { v := i.slice @@ -164,10 +169,11 @@ func (f *UintSliceFlag) Apply(set *flag.FlagSet) error { setValue = f.Value.clone() default: setValue = new(UintSlice) + setValue.WithSeparatorSpec(f.separator) } if val, source, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok && val != "" { - for _, s := range flagSplitMultiValues(val) { + for _, s := range f.separator.flagSplitMultiValues(val) { if err := setValue.Set(strings.TrimSpace(s)); err != nil { return fmt.Errorf("could not parse %q as uint slice value from %s for flag %s: %s", val, source, f.Name, err) } @@ -186,6 +192,10 @@ func (f *UintSliceFlag) Apply(set *flag.FlagSet) error { return nil } +func (f *UintSliceFlag) WithSeparatorSpec(spec separatorSpec) { + f.separator = spec +} + // Get returns the flag’s value in the given Context. func (f *UintSliceFlag) Get(ctx *Context) []uint { return ctx.UintSlice(f.Name) diff --git a/vendor/github.com/urfave/cli/v2/godoc-current.txt b/vendor/github.com/urfave/cli/v2/godoc-current.txt index b8dbf6a..6016bd8 100644 --- a/vendor/github.com/urfave/cli/v2/godoc-current.txt +++ b/vendor/github.com/urfave/cli/v2/godoc-current.txt @@ -141,7 +141,7 @@ USAGE: DESCRIPTION: {{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}} -COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}} +COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}} OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} @@ -318,6 +318,8 @@ type App struct { CustomAppHelpTemplate string // SliceFlagSeparator is used to customize the separator for SliceFlag, the default is "," SliceFlagSeparator string + // DisableSliceFlagSeparator is used to disable SliceFlagSeparator, the default is false + DisableSliceFlagSeparator 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 @@ -355,9 +357,8 @@ func (a *App) RunAndExitOnError() code in the cli.ExitCoder func (a *App) RunAsSubcommand(ctx *Context) (err error) - This is a stub function to keep public API unchanged from old code - - Deprecated: use App.Run or App.RunContext + RunAsSubcommand is for legacy/compatibility purposes only. New code should + only use App.RunContext. This function is slated to be removed in v3. func (a *App) RunContext(ctx context.Context, arguments []string) (err error) RunContext is like Run except it takes a Context that will be passed to @@ -453,6 +454,8 @@ type BoolFlag struct { Count *int + DisableDefaultText bool + Action func(*Context, bool) error // Has unexported fields. } @@ -879,18 +882,20 @@ var BashCompletionFlag Flag = &BoolFlag{ BashCompletionFlag enables bash-completion for all commands and subcommands var HelpFlag Flag = &BoolFlag{ - Name: "help", - Aliases: []string{"h"}, - Usage: "show help", + Name: "help", + Aliases: []string{"h"}, + Usage: "show help", + DisableDefaultText: true, } HelpFlag prints the help for all commands and subcommands. Set to nil to disable the flag. The subcommand will still be added unless HideHelp or HideHelpCommand is set to true. var VersionFlag Flag = &BoolFlag{ - Name: "version", - Aliases: []string{"v"}, - Usage: "print the version", + Name: "version", + Aliases: []string{"v"}, + Usage: "print the version", + DisableDefaultText: true, } VersionFlag prints the version for the application @@ -1032,6 +1037,8 @@ func (f *Float64Slice) String() string func (f *Float64Slice) Value() []float64 Value returns the slice of float64s set by this flag +func (f *Float64Slice) WithSeparatorSpec(spec separatorSpec) + type Float64SliceFlag struct { Name string @@ -1107,6 +1114,8 @@ func (f *Float64SliceFlag) String() string func (f *Float64SliceFlag) TakesValue() bool TakesValue returns true if the flag takes a value, otherwise false +func (f *Float64SliceFlag) WithSeparatorSpec(spec separatorSpec) + type Generic interface { Set(value string) error String() string @@ -1273,6 +1282,8 @@ func (i *Int64Slice) String() string func (i *Int64Slice) Value() []int64 Value returns the slice of ints set by this flag +func (i *Int64Slice) WithSeparatorSpec(spec separatorSpec) + type Int64SliceFlag struct { Name string @@ -1348,6 +1359,8 @@ func (f *Int64SliceFlag) String() string func (f *Int64SliceFlag) TakesValue() bool TakesValue returns true of the flag takes a value, otherwise false +func (f *Int64SliceFlag) WithSeparatorSpec(spec separatorSpec) + type IntFlag struct { Name string @@ -1443,6 +1456,8 @@ func (i *IntSlice) String() string func (i *IntSlice) Value() []int Value returns the slice of ints set by this flag +func (i *IntSlice) WithSeparatorSpec(spec separatorSpec) + type IntSliceFlag struct { Name string @@ -1518,6 +1533,8 @@ func (f *IntSliceFlag) String() string func (f *IntSliceFlag) TakesValue() bool TakesValue returns true of the flag takes a value, otherwise false +func (f *IntSliceFlag) WithSeparatorSpec(spec separatorSpec) + type InvalidFlagAccessFunc func(*Context, string) InvalidFlagAccessFunc is executed when an invalid flag is accessed from the context. @@ -1786,6 +1803,8 @@ func (s *StringSlice) String() string func (s *StringSlice) Value() []string Value returns the slice of strings set by this flag +func (s *StringSlice) WithSeparatorSpec(spec separatorSpec) + type StringSliceFlag struct { Name string @@ -1807,6 +1826,8 @@ type StringSliceFlag struct { TakesFile bool Action func(*Context, []string) error + + KeepSpace bool // Has unexported fields. } StringSliceFlag is a flag with type *StringSlice @@ -1863,6 +1884,8 @@ func (f *StringSliceFlag) String() string func (f *StringSliceFlag) TakesValue() bool TakesValue returns true of the flag takes a value, otherwise false +func (f *StringSliceFlag) WithSeparatorSpec(spec separatorSpec) + type SuggestCommandFunc func(commands []*Command, provided string) string type SuggestFlagFunc func(flags []Flag, provided string, hideHelp bool) string @@ -2057,6 +2080,8 @@ func (i *Uint64Slice) String() string func (i *Uint64Slice) Value() []uint64 Value returns the slice of ints set by this flag +func (i *Uint64Slice) WithSeparatorSpec(spec separatorSpec) + type Uint64SliceFlag struct { Name string @@ -2123,6 +2148,8 @@ func (f *Uint64SliceFlag) String() string func (f *Uint64SliceFlag) TakesValue() bool TakesValue returns true of the flag takes a value, otherwise false +func (f *Uint64SliceFlag) WithSeparatorSpec(spec separatorSpec) + type UintFlag struct { Name string @@ -2218,6 +2245,8 @@ func (i *UintSlice) String() string func (i *UintSlice) Value() []uint Value returns the slice of ints set by this flag +func (i *UintSlice) WithSeparatorSpec(spec separatorSpec) + type UintSliceFlag struct { Name string @@ -2284,6 +2313,8 @@ func (f *UintSliceFlag) String() string func (f *UintSliceFlag) TakesValue() bool TakesValue returns true of the flag takes a value, otherwise false +func (f *UintSliceFlag) WithSeparatorSpec(spec separatorSpec) + type VisibleFlag interface { Flag @@ -2411,6 +2442,9 @@ func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error Apply saves the flagSet for later usage calls, then calls the wrapped Float64SliceFlag.Apply +func (f *Float64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error + ApplyInputSourceValue applies a Float64Slice value if required + type GenericFlag struct { *cli.GenericFlag // Has unexported fields. @@ -2432,12 +2466,16 @@ type InputSourceContext interface { Source() string Int(name string) (int, error) + Int64(name string) (int64, error) + Uint(name string) (uint, error) + Uint64(name string) (uint64, error) Duration(name string) (time.Duration, error) Float64(name string) (float64, error) String(name string) (string, error) StringSlice(name string) ([]string, error) IntSlice(name string) ([]int, error) Int64Slice(name string) ([]int64, error) + Float64Slice(name string) ([]float64, error) Generic(name string) (cli.Generic, error) Bool(name string) (bool, error) @@ -2481,6 +2519,8 @@ func (f *Int64Flag) Apply(set *flag.FlagSet) error Apply saves the flagSet for later usage calls, then calls the wrapped Int64Flag.Apply +func (f *Int64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error + type Int64SliceFlag struct { *cli.Int64SliceFlag // Has unexported fields. @@ -2551,6 +2591,10 @@ func (fsm *MapInputSource) Duration(name string) (time.Duration, error) func (fsm *MapInputSource) Float64(name string) (float64, error) Float64 returns an float64 from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Float64Slice(name string) ([]float64, error) + Float64Slice returns an []float64 from the map if it exists otherwise + returns nil + func (fsm *MapInputSource) Generic(name string) (cli.Generic, error) Generic returns an cli.Generic from the map if it exists otherwise returns nil @@ -2558,6 +2602,9 @@ func (fsm *MapInputSource) Generic(name string) (cli.Generic, error) func (fsm *MapInputSource) Int(name string) (int, error) Int returns an int from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Int64(name string) (int64, error) + Int64 returns an int64 from the map if it exists otherwise returns 0 + func (fsm *MapInputSource) Int64Slice(name string) ([]int64, error) Int64Slice returns an []int64 from the map if it exists otherwise returns nil @@ -2576,6 +2623,12 @@ func (fsm *MapInputSource) StringSlice(name string) ([]string, error) StringSlice returns an []string from the map if it exists otherwise returns nil +func (fsm *MapInputSource) Uint(name string) (uint, error) + Int64 returns an int64 from the map if it exists otherwise returns 0 + +func (fsm *MapInputSource) Uint64(name string) (uint64, error) + UInt64 returns an uint64 from the map if it exists otherwise returns 0 + type PathFlag struct { *cli.PathFlag // Has unexported fields. @@ -2641,6 +2694,8 @@ func (f *Uint64Flag) Apply(set *flag.FlagSet) error Apply saves the flagSet for later usage calls, then calls the wrapped Uint64Flag.Apply +func (f *Uint64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error + type UintFlag struct { *cli.UintFlag // Has unexported fields. @@ -2655,3 +2710,5 @@ func (f *UintFlag) Apply(set *flag.FlagSet) error Apply saves the flagSet for later usage calls, then calls the wrapped UintFlag.Apply +func (f *UintFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error + diff --git a/vendor/github.com/urfave/cli/v2/help.go b/vendor/github.com/urfave/cli/v2/help.go index 2ccd3b7..84bd77b 100644 --- a/vendor/github.com/urfave/cli/v2/help.go +++ b/vendor/github.com/urfave/cli/v2/help.go @@ -42,6 +42,7 @@ var helpCommand = &Command{ // 3 $ app foo // 4 $ app help foo // 5 $ app foo help + // 6 $ app foo -h (with no other sub-commands nor flags defined) // Case 4. when executing a help command set the context to parent // to allow resolution of subsequent args. This will transform @@ -68,7 +69,7 @@ var helpCommand = &Command{ } // Case 3, 5 - if (len(cCtx.Command.Subcommands) == 1 && !cCtx.Command.HideHelp) || + if (len(cCtx.Command.Subcommands) == 1 && !cCtx.Command.HideHelp && !cCtx.Command.HideHelpCommand) || (len(cCtx.Command.Subcommands) == 0 && cCtx.Command.HideHelp) { templ := cCtx.Command.CustomHelpTemplate if templ == "" { @@ -77,6 +78,8 @@ var helpCommand = &Command{ HelpPrinter(cCtx.App.Writer, templ, cCtx.Command) return nil } + + // Case 6, handling incorporated in the callee itself return ShowSubcommandHelp(cCtx) }, } @@ -206,9 +209,15 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) { func DefaultCompleteWithFlags(cmd *Command) func(cCtx *Context) { return func(cCtx *Context) { + var lastArg string + + // TODO: This shouldnt depend on os.Args rather it should + // depend on root arguments passed to App if len(os.Args) > 2 { - lastArg := os.Args[len(os.Args)-2] + lastArg = os.Args[len(os.Args)-2] + } + if lastArg != "" { if strings.HasPrefix(lastArg, "-") { if cmd != nil { printFlagSuggestions(lastArg, cmd.Flags, cCtx.App.Writer) @@ -227,7 +236,7 @@ func DefaultCompleteWithFlags(cmd *Command) func(cCtx *Context) { return } - printCommandSuggestions(cCtx.App.Commands, cCtx.App.Writer) + printCommandSuggestions(cCtx.Command.Subcommands, cCtx.App.Writer) } } @@ -292,8 +301,12 @@ func ShowSubcommandHelp(cCtx *Context) error { if cCtx == nil { return nil } - - HelpPrinter(cCtx.App.Writer, SubcommandHelpTemplate, cCtx.Command) + // use custom template when provided (fixes #1703) + templ := SubcommandHelpTemplate + if cCtx.Command != nil && cCtx.Command.CustomHelpTemplate != "" { + templ = cCtx.Command.CustomHelpTemplate + } + HelpPrinter(cCtx.App.Writer, templ, cCtx.Command) return nil } @@ -308,15 +321,15 @@ func printVersion(cCtx *Context) { // ShowCompletions prints the lists of commands within a given context func ShowCompletions(cCtx *Context) { - a := cCtx.App - if a != nil && a.BashComplete != nil { - a.BashComplete(cCtx) + c := cCtx.Command + if c != nil && c.BashComplete != nil { + c.BashComplete(cCtx) } } // ShowCommandCompletions prints the custom completions for a given command func ShowCommandCompletions(ctx *Context, command string) { - c := ctx.App.Command(command) + c := ctx.Command.Command(command) if c != nil { if c.BashComplete != nil { c.BashComplete(ctx) @@ -363,17 +376,26 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0) t := template.Must(template.New("help").Funcs(funcMap).Parse(templ)) - t.New("helpNameTemplate").Parse(helpNameTemplate) - t.New("usageTemplate").Parse(usageTemplate) - t.New("descriptionTemplate").Parse(descriptionTemplate) - t.New("visibleCommandTemplate").Parse(visibleCommandTemplate) - t.New("copyrightTemplate").Parse(copyrightTemplate) - t.New("versionTemplate").Parse(versionTemplate) - t.New("visibleFlagCategoryTemplate").Parse(visibleFlagCategoryTemplate) - t.New("visibleFlagTemplate").Parse(visibleFlagTemplate) - t.New("visibleGlobalFlagCategoryTemplate").Parse(strings.Replace(visibleFlagCategoryTemplate, "OPTIONS", "GLOBAL OPTIONS", -1)) - t.New("authorsTemplate").Parse(authorsTemplate) - t.New("visibleCommandCategoryTemplate").Parse(visibleCommandCategoryTemplate) + templates := map[string]string{ + "helpNameTemplate": helpNameTemplate, + "usageTemplate": usageTemplate, + "descriptionTemplate": descriptionTemplate, + "visibleCommandTemplate": visibleCommandTemplate, + "copyrightTemplate": copyrightTemplate, + "versionTemplate": versionTemplate, + "visibleFlagCategoryTemplate": visibleFlagCategoryTemplate, + "visibleFlagTemplate": visibleFlagTemplate, + "visibleGlobalFlagCategoryTemplate": strings.Replace(visibleFlagCategoryTemplate, "OPTIONS", "GLOBAL OPTIONS", -1), + "authorsTemplate": authorsTemplate, + "visibleCommandCategoryTemplate": visibleCommandCategoryTemplate, + } + for name, value := range templates { + if _, err := t.New(name).Parse(value); err != nil { + if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" { + _, _ = fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err) + } + } + } err := t.Execute(w, data) if err != nil { @@ -402,6 +424,9 @@ func checkVersion(cCtx *Context) bool { } func checkHelp(cCtx *Context) bool { + if HelpFlag == nil { + return false + } found := false for _, name := range HelpFlag.Names() { if cCtx.Bool(name) { @@ -413,24 +438,6 @@ func checkHelp(cCtx *Context) bool { 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(cCtx *Context) bool { - if cCtx.Bool("h") || cCtx.Bool("help") { - _ = ShowSubcommandHelp(cCtx) - return true - } - - return false -} - func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) { if !a.EnableBashCompletion { return false, arguments @@ -453,7 +460,7 @@ func checkCompletions(cCtx *Context) bool { if args := cCtx.Args(); args.Present() { name := args.First() - if cmd := cCtx.App.Command(name); cmd != nil { + if cmd := cCtx.Command.Command(name); cmd != nil { // let the command handle the completion return false } @@ -463,15 +470,6 @@ func checkCompletions(cCtx *Context) bool { return true } -func checkCommandCompletions(c *Context, name string) bool { - if !c.shellComplete { - return false - } - - ShowCommandCompletions(c, name) - return true -} - func subtract(a, b int) int { return a - b } diff --git a/vendor/github.com/urfave/cli/v2/mkdocs-requirements.txt b/vendor/github.com/urfave/cli/v2/mkdocs-reqs.txt similarity index 100% rename from vendor/github.com/urfave/cli/v2/mkdocs-requirements.txt rename to vendor/github.com/urfave/cli/v2/mkdocs-reqs.txt diff --git a/vendor/github.com/urfave/cli/v2/mkdocs.yml b/vendor/github.com/urfave/cli/v2/mkdocs.yml index 02657b9..f7bfd41 100644 --- a/vendor/github.com/urfave/cli/v2/mkdocs.yml +++ b/vendor/github.com/urfave/cli/v2/mkdocs.yml @@ -1,7 +1,7 @@ # NOTE: the mkdocs dependencies will need to be installed out of # band until this whole thing gets more automated: # -# pip install -r mkdocs-requirements.txt +# pip install -r mkdocs-reqs.txt # site_name: urfave/cli diff --git a/vendor/github.com/urfave/cli/v2/sliceflag.go b/vendor/github.com/urfave/cli/v2/sliceflag.go index 7dea357..b2ca590 100644 --- a/vendor/github.com/urfave/cli/v2/sliceflag.go +++ b/vendor/github.com/urfave/cli/v2/sliceflag.go @@ -1,6 +1,3 @@ -//go:build go1.18 -// +build go1.18 - package cli import ( diff --git a/vendor/github.com/urfave/cli/v2/sliceflag_pre18.go b/vendor/github.com/urfave/cli/v2/sliceflag_pre18.go deleted file mode 100644 index 1173ae7..0000000 --- a/vendor/github.com/urfave/cli/v2/sliceflag_pre18.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build !go1.18 -// +build !go1.18 - -package cli - -import ( - "flag" -) - -func unwrapFlagValue(v flag.Value) flag.Value { return v } diff --git a/vendor/github.com/urfave/cli/v2/suggestions.go b/vendor/github.com/urfave/cli/v2/suggestions.go index 87fa905..c73a001 100644 --- a/vendor/github.com/urfave/cli/v2/suggestions.go +++ b/vendor/github.com/urfave/cli/v2/suggestions.go @@ -21,7 +21,7 @@ func suggestFlag(flags []Flag, provided string, hideHelp bool) string { for _, flag := range flags { flagNames := flag.Names() - if !hideHelp { + if !hideHelp && HelpFlag != nil { flagNames = append(flagNames, HelpFlag.Names()...) } for _, name := range flagNames { diff --git a/vendor/github.com/urfave/cli/v2/template.go b/vendor/github.com/urfave/cli/v2/template.go index b565ba6..da98890 100644 --- a/vendor/github.com/urfave/cli/v2/template.go +++ b/vendor/github.com/urfave/cli/v2/template.go @@ -88,7 +88,7 @@ USAGE: DESCRIPTION: {{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}} -COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}} +COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}} OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} diff --git a/vendor/github.com/urfave/cli/v2/zz_generated.flags.go b/vendor/github.com/urfave/cli/v2/zz_generated.flags.go index 7d0a267..f2fc8c8 100644 --- a/vendor/github.com/urfave/cli/v2/zz_generated.flags.go +++ b/vendor/github.com/urfave/cli/v2/zz_generated.flags.go @@ -23,7 +23,10 @@ type Float64SliceFlag struct { Aliases []string EnvVars []string - defaultValue *Float64Slice + defaultValue *Float64Slice + defaultValueSet bool + + separator separatorSpec Action func(*Context, []float64) error } @@ -67,7 +70,8 @@ type GenericFlag struct { Aliases []string EnvVars []string - defaultValue Generic + defaultValue Generic + defaultValueSet bool TakesFile bool @@ -118,7 +122,10 @@ type Int64SliceFlag struct { Aliases []string EnvVars []string - defaultValue *Int64Slice + defaultValue *Int64Slice + defaultValueSet bool + + separator separatorSpec Action func(*Context, []int64) error } @@ -162,7 +169,10 @@ type IntSliceFlag struct { Aliases []string EnvVars []string - defaultValue *IntSlice + defaultValue *IntSlice + defaultValueSet bool + + separator separatorSpec Action func(*Context, []int) error } @@ -206,7 +216,8 @@ type PathFlag struct { Aliases []string EnvVars []string - defaultValue Path + defaultValue Path + defaultValueSet bool TakesFile bool @@ -257,11 +268,16 @@ type StringSliceFlag struct { Aliases []string EnvVars []string - defaultValue *StringSlice + defaultValue *StringSlice + defaultValueSet bool + + separator separatorSpec TakesFile bool Action func(*Context, []string) error + + KeepSpace bool } // IsSet returns whether or not the flag has been set through env or file @@ -303,7 +319,8 @@ type TimestampFlag struct { Aliases []string EnvVars []string - defaultValue *Timestamp + defaultValue *Timestamp + defaultValueSet bool Layout string @@ -356,7 +373,10 @@ type Uint64SliceFlag struct { Aliases []string EnvVars []string - defaultValue *Uint64Slice + defaultValue *Uint64Slice + defaultValueSet bool + + separator separatorSpec Action func(*Context, []uint64) error } @@ -400,7 +420,10 @@ type UintSliceFlag struct { Aliases []string EnvVars []string - defaultValue *UintSlice + defaultValue *UintSlice + defaultValueSet bool + + separator separatorSpec Action func(*Context, []uint) error } @@ -444,10 +467,13 @@ type BoolFlag struct { Aliases []string EnvVars []string - defaultValue bool + defaultValue bool + defaultValueSet bool Count *int + DisableDefaultText bool + Action func(*Context, bool) error } @@ -495,7 +521,8 @@ type Float64Flag struct { Aliases []string EnvVars []string - defaultValue float64 + defaultValue float64 + defaultValueSet bool Action func(*Context, float64) error } @@ -544,7 +571,8 @@ type IntFlag struct { Aliases []string EnvVars []string - defaultValue int + defaultValue int + defaultValueSet bool Base int @@ -595,7 +623,8 @@ type Int64Flag struct { Aliases []string EnvVars []string - defaultValue int64 + defaultValue int64 + defaultValueSet bool Base int @@ -646,7 +675,8 @@ type StringFlag struct { Aliases []string EnvVars []string - defaultValue string + defaultValue string + defaultValueSet bool TakesFile bool @@ -697,7 +727,8 @@ type DurationFlag struct { Aliases []string EnvVars []string - defaultValue time.Duration + defaultValue time.Duration + defaultValueSet bool Action func(*Context, time.Duration) error } @@ -746,7 +777,8 @@ type UintFlag struct { Aliases []string EnvVars []string - defaultValue uint + defaultValue uint + defaultValueSet bool Base int @@ -797,7 +829,8 @@ type Uint64Flag struct { Aliases []string EnvVars []string - defaultValue uint64 + defaultValue uint64 + defaultValueSet bool Base int diff --git a/vendor/modules.txt b/vendor/modules.txt index a5fc874..955e837 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -43,7 +43,7 @@ github.com/rivo/uniseg # github.com/russross/blackfriday/v2 v2.1.0 ## explicit github.com/russross/blackfriday/v2 -# github.com/urfave/cli/v2 v2.23.5 +# github.com/urfave/cli/v2 v2.26.0 ## explicit; go 1.18 github.com/urfave/cli/v2 # github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673