Fix test cases for context, docs, errors, fish, flags and funcs
This commit is contained in:
parent
f29d98aa2d
commit
2024bed22a
45
context.go
45
context.go
@ -33,6 +33,9 @@ func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context {
|
|||||||
c.Context = parentCtx.Context
|
c.Context = parentCtx.Context
|
||||||
c.shellComplete = parentCtx.shellComplete
|
c.shellComplete = parentCtx.shellComplete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Command = &Command{}
|
||||||
|
|
||||||
if c.Context == nil {
|
if c.Context == nil {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
go func() {
|
go func() {
|
||||||
@ -59,6 +62,7 @@ func (c *Context) Set(name, value string) error {
|
|||||||
|
|
||||||
// IsSet determines if the flag was actually set
|
// IsSet determines if the flag was actually set
|
||||||
func (c *Context) IsSet(name string) bool {
|
func (c *Context) IsSet(name string) bool {
|
||||||
|
if fs := lookupFlagSet(name, c); fs != nil {
|
||||||
if fs := lookupFlagSet(name, c); fs != nil {
|
if fs := lookupFlagSet(name, c); fs != nil {
|
||||||
isSet := false
|
isSet := false
|
||||||
fs.Visit(func(f *flag.Flag) {
|
fs.Visit(func(f *flag.Flag) {
|
||||||
@ -66,6 +70,10 @@ func (c *Context) IsSet(name string) bool {
|
|||||||
isSet = true
|
isSet = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if isSet {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// XXX hack to support IsSet for flags with EnvVar
|
// XXX hack to support IsSet for flags with EnvVar
|
||||||
//
|
//
|
||||||
@ -78,16 +86,9 @@ func (c *Context) IsSet(name string) bool {
|
|||||||
// variables is available.
|
// variables is available.
|
||||||
//
|
//
|
||||||
// See https://github.com/urfave/cli/issues/294 for additional discussion
|
// See https://github.com/urfave/cli/issues/294 for additional discussion
|
||||||
flags := c.Command.Flags
|
f := lookupFlag(name, c)
|
||||||
if c.Command.Name == "" { // cannot == Command{} since it contains slice types
|
if f == nil {
|
||||||
if c.App != nil {
|
return false
|
||||||
flags = c.App.Flags
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, f := range flags {
|
|
||||||
for _, name := range f.Names() {
|
|
||||||
if isSet, ok := c.setFlags[name]; isSet || !ok {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val := reflect.ValueOf(f)
|
val := reflect.ValueOf(f)
|
||||||
@ -96,27 +97,17 @@ func (c *Context) IsSet(name string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filePathValue := val.FieldByName("FilePath")
|
filePathValue := val.FieldByName("FilePath")
|
||||||
if filePathValue.IsValid() {
|
if !filePathValue.IsValid() {
|
||||||
eachName(filePathValue.String(), func(filePath string) {
|
return false
|
||||||
if _, err := os.Stat(filePath); err == nil {
|
|
||||||
c.setFlags[name] = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
envVarValues := val.FieldByName("EnvVars")
|
envVarValues := val.FieldByName("EnvVars")
|
||||||
if envVarValues.IsValid() {
|
if !envVarValues.IsValid() {
|
||||||
for _, envVar := range envVarValues.Interface().([]string) {
|
return false
|
||||||
envVar = strings.TrimSpace(envVar)
|
|
||||||
if _, ok := syscall.Getenv(envVar); ok {
|
|
||||||
c.setFlags[name] = true
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, ok := flagFromEnvOrFile(envVarValues.Interface().([]string), filePathValue.Interface().(string))
|
||||||
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -452,7 +452,7 @@ func TestCheckRequiredFlags(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "required_and_present_via_env_var",
|
testCase: "required_and_present_via_env_var",
|
||||||
flags: []Flag{
|
flags: []Flag{
|
||||||
&StringFlag{Name: "requiredFlag", Required: true, EnvVar: "REQUIRED_FLAG"},
|
&StringFlag{Name: "requiredFlag", Required: true, EnvVars: []string{"REQUIRED_FLAG"}},
|
||||||
},
|
},
|
||||||
envVarInput: [2]string{"REQUIRED_FLAG", "true"},
|
envVarInput: [2]string{"REQUIRED_FLAG", "true"},
|
||||||
},
|
},
|
||||||
@ -477,7 +477,7 @@ func TestCheckRequiredFlags(t *testing.T) {
|
|||||||
testCase: "required_and_optional_and_optional_present_via_env_var",
|
testCase: "required_and_optional_and_optional_present_via_env_var",
|
||||||
flags: []Flag{
|
flags: []Flag{
|
||||||
&StringFlag{Name: "requiredFlag", Required: true},
|
&StringFlag{Name: "requiredFlag", Required: true},
|
||||||
&StringFlag{Name: "optionalFlag", EnvVar: "OPTIONAL_FLAG"},
|
&StringFlag{Name: "optionalFlag", EnvVars: []string{"OPTIONAL_FLAG"}},
|
||||||
},
|
},
|
||||||
envVarInput: [2]string{"OPTIONAL_FLAG", "true"},
|
envVarInput: [2]string{"OPTIONAL_FLAG", "true"},
|
||||||
expectedAnError: true,
|
expectedAnError: true,
|
||||||
@ -519,14 +519,14 @@ func TestCheckRequiredFlags(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "required_flag_with_short_name",
|
testCase: "required_flag_with_short_name",
|
||||||
flags: []Flag{
|
flags: []Flag{
|
||||||
&StringSliceFlag{Name: "names, N", Required: true},
|
&StringSliceFlag{Name: "names", Aliases: []string{"N"}, Required: true},
|
||||||
},
|
},
|
||||||
parseInput: []string{"-N", "asd", "-N", "qwe"},
|
parseInput: []string{"-N", "asd", "-N", "qwe"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testCase: "required_flag_with_multiple_short_names",
|
testCase: "required_flag_with_multiple_short_names",
|
||||||
flags: []Flag{
|
flags: []Flag{
|
||||||
&StringSliceFlag{Name: "names, N, n", Required: true},
|
&StringSliceFlag{Name: "names", Aliases: []string{"N", "n"}, Required: true},
|
||||||
},
|
},
|
||||||
parseInput: []string{"-n", "asd", "-n", "qwe"},
|
parseInput: []string{"-n", "asd", "-n", "qwe"},
|
||||||
},
|
},
|
||||||
@ -543,12 +543,12 @@ func TestCheckRequiredFlags(t *testing.T) {
|
|||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
_ = os.Setenv(test.envVarInput[0], test.envVarInput[1])
|
_ = os.Setenv(test.envVarInput[0], test.envVarInput[1])
|
||||||
}
|
}
|
||||||
ctx := &Context{}
|
c := &Context{}
|
||||||
context := NewContext(ctx.App, set, ctx)
|
ctx := NewContext(c.App, set, c)
|
||||||
context.Command.Flags = test.flags
|
ctx.Command.Flags = test.flags
|
||||||
|
|
||||||
// logic under test
|
// logic under test
|
||||||
err := checkRequiredFlags(test.flags, context)
|
err := checkRequiredFlags(test.flags, ctx)
|
||||||
|
|
||||||
// assertions
|
// assertions
|
||||||
if test.expectedAnError && err == nil {
|
if test.expectedAnError && err == nil {
|
||||||
|
9
docs.go
9
docs.go
@ -53,10 +53,9 @@ func (a *App) writeDocTemplate(w io.Writer) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareCommands(commands []Command, level int) []string {
|
func prepareCommands(commands []*Command, level int) []string {
|
||||||
coms := []string{}
|
var coms []string
|
||||||
for i := range commands {
|
for _, command := range commands {
|
||||||
command := &commands[i]
|
|
||||||
if command.Hidden {
|
if command.Hidden {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -110,7 +109,7 @@ func prepareFlags(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
modifiedArg := opener
|
modifiedArg := opener
|
||||||
for _, s := range strings.Split(flag.GetName(), ",") {
|
for _, s := range flag.Names() {
|
||||||
trimmed := strings.TrimSpace(s)
|
trimmed := strings.TrimSpace(s)
|
||||||
if len(modifiedArg) > len(opener) {
|
if len(modifiedArg) > len(opener) {
|
||||||
modifiedArg += sep
|
modifiedArg += sep
|
||||||
|
37
docs_test.go
37
docs_test.go
@ -9,38 +9,43 @@ func testApp() *App {
|
|||||||
app := NewApp()
|
app := NewApp()
|
||||||
app.Name = "greet"
|
app.Name = "greet"
|
||||||
app.Flags = []Flag{
|
app.Flags = []Flag{
|
||||||
StringFlag{
|
&StringFlag{
|
||||||
Name: "socket, s",
|
Name: "socket",
|
||||||
|
Aliases: []string{"s"},
|
||||||
Usage: "some 'usage' text",
|
Usage: "some 'usage' text",
|
||||||
Value: "value",
|
Value: "value",
|
||||||
TakesFile: true,
|
TakesFile: true,
|
||||||
},
|
},
|
||||||
StringFlag{Name: "flag, fl, f"},
|
&StringFlag{Name: "flag", Aliases: []string{" fl", "f"}},
|
||||||
BoolFlag{
|
&BoolFlag{
|
||||||
Name: "another-flag, b",
|
Name: "another-flag",
|
||||||
|
Aliases: []string{"b"},
|
||||||
Usage: "another usage text",
|
Usage: "another usage text",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
app.Commands = []Command{{
|
app.Commands = []*Command{{
|
||||||
Aliases: []string{"c"},
|
Aliases: []string{"c"},
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
StringFlag{
|
&StringFlag{
|
||||||
Name: "flag, fl, f",
|
Name: "flag",
|
||||||
|
Aliases: []string{" fl", "f"},
|
||||||
TakesFile: true,
|
TakesFile: true,
|
||||||
},
|
},
|
||||||
BoolFlag{
|
&BoolFlag{
|
||||||
Name: "another-flag, b",
|
Name: "another-flag",
|
||||||
|
Aliases: []string{"b"},
|
||||||
Usage: "another usage text",
|
Usage: "another usage text",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Name: "config",
|
Name: "config",
|
||||||
Usage: "another usage test",
|
Usage: "another usage test",
|
||||||
Subcommands: []Command{{
|
Subcommands: []*Command{{
|
||||||
Aliases: []string{"s", "ss"},
|
Aliases: []string{"s", "ss"},
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
StringFlag{Name: "sub-flag, sub-fl, s"},
|
&StringFlag{Name: "sub-flag", Aliases: []string{"sub-fl", "s"}},
|
||||||
BoolFlag{
|
&BoolFlag{
|
||||||
Name: "sub-command-flag, s",
|
Name: "sub-command-flag",
|
||||||
|
Aliases: []string{"s"},
|
||||||
Usage: "some usage text",
|
Usage: "some usage text",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -59,9 +64,7 @@ func testApp() *App {
|
|||||||
}}
|
}}
|
||||||
app.UsageText = "app [first_arg] [second_arg]"
|
app.UsageText = "app [first_arg] [second_arg]"
|
||||||
app.Usage = "Some app"
|
app.Usage = "Some app"
|
||||||
app.Author = "Harrison"
|
app.Authors = []*Author{{Name: "Harrison", Email: "harrison@lolwut.com"}, {Name: "Oliver Allen", Email: "oliver@toyshop.com"}}
|
||||||
app.Email = "harrison@lolwut.com"
|
|
||||||
app.Authors = []Author{{Name: "Oliver Allen", Email: "oliver@toyshop.com"}}
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
errors.go
17
errors.go
@ -59,33 +59,30 @@ type ExitCoder interface {
|
|||||||
ExitCode() int
|
ExitCode() int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExitError struct {
|
type exitError struct {
|
||||||
exitCode int
|
exitCode int
|
||||||
message interface{}
|
message interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewExitError makes a new *ExitError
|
// NewExitError makes a new *exitError
|
||||||
func NewExitError(message interface{}, exitCode int) *ExitError {
|
func NewExitError(message interface{}, exitCode int) ExitCoder {
|
||||||
return &ExitError{
|
return Exit(message, exitCode)
|
||||||
exitCode: exitCode,
|
|
||||||
message: message,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit wraps a message and exit code into an ExitCoder suitable for handling by
|
// Exit wraps a message and exit code into an ExitCoder suitable for handling by
|
||||||
// HandleExitCoder
|
// HandleExitCoder
|
||||||
func Exit(message interface{}, exitCode int) ExitCoder {
|
func Exit(message interface{}, exitCode int) ExitCoder {
|
||||||
return &ExitError{
|
return &exitError{
|
||||||
exitCode: exitCode,
|
exitCode: exitCode,
|
||||||
message: message,
|
message: message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ee *ExitError) Error() string {
|
func (ee *exitError) Error() string {
|
||||||
return fmt.Sprintf("%v", ee.message)
|
return fmt.Sprintf("%v", ee.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ee *ExitError) ExitCode() int {
|
func (ee *exitError) ExitCode() int {
|
||||||
return ee.exitCode
|
return ee.exitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
fish.go
14
fish.go
@ -64,11 +64,9 @@ func (a *App) writeFishCompletionTemplate(w io.Writer) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) prepareFishCommands(commands []Command, allCommands *[]string, previousCommands []string) []string {
|
func (a *App) prepareFishCommands(commands []*Command, allCommands *[]string, previousCommands []string) []string {
|
||||||
completions := []string{}
|
completions := []string{}
|
||||||
for i := range commands {
|
for _, command := range commands {
|
||||||
command := &commands[i]
|
|
||||||
|
|
||||||
if command.Hidden {
|
if command.Hidden {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -131,7 +129,7 @@ func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string
|
|||||||
|
|
||||||
fishAddFileFlag(f, completion)
|
fishAddFileFlag(f, completion)
|
||||||
|
|
||||||
for idx, opt := range strings.Split(flag.GetName(), ",") {
|
for idx, opt := range flag.Names() {
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
completion.WriteString(fmt.Sprintf(
|
completion.WriteString(fmt.Sprintf(
|
||||||
" -l %s", strings.TrimSpace(opt),
|
" -l %s", strings.TrimSpace(opt),
|
||||||
@ -161,15 +159,15 @@ func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string
|
|||||||
|
|
||||||
func fishAddFileFlag(flag Flag, completion *strings.Builder) {
|
func fishAddFileFlag(flag Flag, completion *strings.Builder) {
|
||||||
switch f := flag.(type) {
|
switch f := flag.(type) {
|
||||||
case GenericFlag:
|
case *GenericFlag:
|
||||||
if f.TakesFile {
|
if f.TakesFile {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case StringFlag:
|
case *StringFlag:
|
||||||
if f.TakesFile {
|
if f.TakesFile {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case StringSliceFlag:
|
case *StringSliceFlag:
|
||||||
if f.TakesFile {
|
if f.TakesFile {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
6
flag.go
6
flag.go
@ -49,7 +49,8 @@ var BashCompletionFlag Flag = &BoolFlag{
|
|||||||
|
|
||||||
// VersionFlag prints the version for the application
|
// VersionFlag prints the version for the application
|
||||||
var VersionFlag Flag = &BoolFlag{
|
var VersionFlag Flag = &BoolFlag{
|
||||||
Name: "version, v",
|
Name: "version",
|
||||||
|
Aliases: []string{"v"},
|
||||||
Usage: "print the version",
|
Usage: "print the version",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +58,8 @@ var VersionFlag Flag = &BoolFlag{
|
|||||||
// Set to nil to disable the flag. The subcommand
|
// Set to nil to disable the flag. The subcommand
|
||||||
// will still be added unless HideHelp is set to true.
|
// will still be added unless HideHelp is set to true.
|
||||||
var HelpFlag Flag = &BoolFlag{
|
var HelpFlag Flag = &BoolFlag{
|
||||||
Name: "help, h",
|
Name: "help",
|
||||||
|
Aliases: []string{"h"},
|
||||||
Usage: "show help",
|
Usage: "show help",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,10 @@ func (f *IntFlag) Apply(set *flag.FlagSet) error {
|
|||||||
// Int looks up the value of a local IntFlag, returns
|
// Int looks up the value of a local IntFlag, returns
|
||||||
// 0 if not found
|
// 0 if not found
|
||||||
func (c *Context) Int(name string) int {
|
func (c *Context) Int(name string) int {
|
||||||
return lookupInt(name, c.flagSet)
|
if fs := lookupFlagSet(name, c); fs != nil {
|
||||||
|
return lookupInt(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlobalInt looks up the value of a global IntFlag, returns
|
// GlobalInt looks up the value of a global IntFlag, returns
|
||||||
|
@ -78,7 +78,10 @@ func (f *Int64Flag) Apply(set *flag.FlagSet) error {
|
|||||||
// Int64 looks up the value of a local Int64Flag, returns
|
// Int64 looks up the value of a local Int64Flag, returns
|
||||||
// 0 if not found
|
// 0 if not found
|
||||||
func (c *Context) Int64(name string) int64 {
|
func (c *Context) Int64(name string) int64 {
|
||||||
return lookupInt64(name, c.flagSet)
|
if fs := lookupFlagSet(name, c); fs != nil {
|
||||||
|
return lookupInt64(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlobalInt64 looks up the value of a global Int64Flag, returns
|
// GlobalInt64 looks up the value of a global Int64Flag, returns
|
||||||
|
@ -7,7 +7,6 @@ type PathFlag struct {
|
|||||||
Aliases []string
|
Aliases []string
|
||||||
Usage string
|
Usage string
|
||||||
EnvVars []string
|
EnvVars []string
|
||||||
EnvVar string
|
|
||||||
FilePath string
|
FilePath string
|
||||||
Required bool
|
Required bool
|
||||||
Hidden bool
|
Hidden bool
|
||||||
@ -58,7 +57,7 @@ func (f *PathFlag) Apply(set *flag.FlagSet) error {
|
|||||||
for _, name := range f.Names() {
|
for _, name := range f.Names() {
|
||||||
if f.Destination != nil {
|
if f.Destination != nil {
|
||||||
set.StringVar(f.Destination, name, f.Value, f.Usage)
|
set.StringVar(f.Destination, name, f.Value, f.Usage)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
set.String(name, f.Value, f.Usage)
|
set.String(name, f.Value, f.Usage)
|
||||||
}
|
}
|
||||||
@ -69,7 +68,11 @@ func (f *PathFlag) Apply(set *flag.FlagSet) error {
|
|||||||
// String looks up the value of a local PathFlag, returns
|
// String looks up the value of a local PathFlag, returns
|
||||||
// "" if not found
|
// "" if not found
|
||||||
func (c *Context) Path(name string) string {
|
func (c *Context) Path(name string) string {
|
||||||
return lookupPath(name, c.flagSet)
|
if fs := lookupFlagSet(name, c); fs != nil {
|
||||||
|
return lookupPath(name, fs)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupPath(name string, set *flag.FlagSet) string {
|
func lookupPath(name string, set *flag.FlagSet) string {
|
||||||
|
@ -8,7 +8,6 @@ type StringFlag struct {
|
|||||||
Aliases []string
|
Aliases []string
|
||||||
Usage string
|
Usage string
|
||||||
EnvVars []string
|
EnvVars []string
|
||||||
EnvVar string
|
|
||||||
FilePath string
|
FilePath string
|
||||||
Required bool
|
Required bool
|
||||||
Hidden bool
|
Hidden bool
|
||||||
@ -59,7 +58,7 @@ func (s *StringFlag) Apply(set *flag.FlagSet) error {
|
|||||||
for _, name := range s.Names() {
|
for _, name := range s.Names() {
|
||||||
if s.Destination != nil {
|
if s.Destination != nil {
|
||||||
set.StringVar(s.Destination, name, s.Value, s.Usage)
|
set.StringVar(s.Destination, name, s.Value, s.Usage)
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
set.String(name, s.Value, s.Usage)
|
set.String(name, s.Value, s.Usage)
|
||||||
}
|
}
|
||||||
@ -70,7 +69,10 @@ func (s *StringFlag) Apply(set *flag.FlagSet) error {
|
|||||||
// String looks up the value of a local StringFlag, returns
|
// String looks up the value of a local StringFlag, returns
|
||||||
// "" if not found
|
// "" if not found
|
||||||
func (c *Context) String(name string) string {
|
func (c *Context) String(name string) string {
|
||||||
return lookupString(name, c.flagSet)
|
if fs := lookupFlagSet(name, c); fs != nil {
|
||||||
|
return lookupString(name, fs)
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlobalString looks up the value of a global StringFlag, returns
|
// GlobalString looks up the value of a global StringFlag, returns
|
||||||
|
@ -130,7 +130,10 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
|
|||||||
// StringSlice looks up the value of a local StringSliceFlag, returns
|
// StringSlice looks up the value of a local StringSliceFlag, returns
|
||||||
// nil if not found
|
// nil if not found
|
||||||
func (c *Context) StringSlice(name string) []string {
|
func (c *Context) StringSlice(name string) []string {
|
||||||
return lookupStringSlice(name, c.flagSet)
|
if fs := lookupFlagSet(name, c); fs != nil {
|
||||||
|
return lookupStringSlice(name, fs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlobalStringSlice looks up the value of a global StringSliceFlag, returns
|
// GlobalStringSlice looks up the value of a global StringSliceFlag, returns
|
||||||
|
215
flag_test.go
215
flag_test.go
@ -24,8 +24,8 @@ var boolFlagTests = []struct {
|
|||||||
|
|
||||||
func TestBoolFlagHelpOutput(t *testing.T) {
|
func TestBoolFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range boolFlagTests {
|
for _, test := range boolFlagTests {
|
||||||
flag := &BoolFlag{Name: test.name}
|
fl := &BoolFlag{Name: test.name}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
@ -37,7 +37,7 @@ func TestBoolFlagApply_SetsAllNames(t *testing.T) {
|
|||||||
v := false
|
v := false
|
||||||
fl := BoolFlag{Name: "wat", Aliases: []string{"W", "huh"}, Destination: &v}
|
fl := BoolFlag{Name: "wat", Aliases: []string{"W", "huh"}, Destination: &v}
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
fl.Apply(set)
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
err := set.Parse([]string{"--wat", "-W", "--huh"})
|
err := set.Parse([]string{"--wat", "-W", "--huh"})
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
@ -113,16 +113,16 @@ func TestFlagsFromEnv(t *testing.T) {
|
|||||||
{"foo,bar", &Parser{"foo", "bar"}, &GenericFlag{Name: "names", Value: &Parser{}, EnvVars: []string{"NAMES"}}, ""},
|
{"foo,bar", &Parser{"foo", "bar"}, &GenericFlag{Name: "names", Value: &Parser{}, EnvVars: []string{"NAMES"}}, ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
//<<<<<<< HEAD
|
//<<<<<<< HEAD
|
||||||
// for i, test := range flagTests {
|
// for i, test := range flagTests {
|
||||||
// os.Clearenv()
|
// os.Clearenv()
|
||||||
// envVarSlice := reflect.Indirect(reflect.ValueOf(test.flag)).FieldByName("EnvVars").Slice(0, 1)
|
// envVarSlice := reflect.Indirect(reflect.ValueOf(test.flag)).FieldByName("EnvVars").Slice(0, 1)
|
||||||
// os.Setenv(envVarSlice.Index(0).String(), test.input)
|
// os.Setenv(envVarSlice.Index(0).String(), test.input)
|
||||||
//=======
|
//=======
|
||||||
for i, test := range flagTests {
|
for i, test := range flagTests {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
_ = os.Setenv(reflect.ValueOf(test.flag).FieldByName("EnvVar").String(), test.input)
|
_ = os.Setenv(reflect.ValueOf(test.flag).FieldByName("EnvVar").String(), test.input)
|
||||||
//>>>>>>> master
|
//>>>>>>> master
|
||||||
a := App{
|
a := App{
|
||||||
Flags: []Flag{test.flag},
|
Flags: []Flag{test.flag},
|
||||||
Action: func(ctx *Context) error {
|
Action: func(ctx *Context) error {
|
||||||
@ -168,8 +168,8 @@ var stringFlagTests = []struct {
|
|||||||
|
|
||||||
func TestStringFlagHelpOutput(t *testing.T) {
|
func TestStringFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range stringFlagTests {
|
for _, test := range stringFlagTests {
|
||||||
flag := &StringFlag{Name: test.name, Aliases: test.aliases, Usage: test.usage, Value: test.value}
|
fl := &StringFlag{Name: test.name, Aliases: test.aliases, Usage: test.usage, Value: test.value}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
@ -178,9 +178,9 @@ func TestStringFlagHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStringFlagDefaultText(t *testing.T) {
|
func TestStringFlagDefaultText(t *testing.T) {
|
||||||
flag := &StringFlag{Name: "foo", Aliases: nil, Usage: "amount of `foo` requested", Value: "none", DefaultText: "all of it"}
|
fl := &StringFlag{Name: "foo", Aliases: nil, Usage: "amount of `foo` requested", Value: "none", DefaultText: "all of it"}
|
||||||
expected := "--foo foo\tamount of foo requested (default: all of it)"
|
expected := "--foo foo\tamount of foo requested (default: all of it)"
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != expected {
|
if output != expected {
|
||||||
t.Errorf("%q does not match %q", output, expected)
|
t.Errorf("%q does not match %q", output, expected)
|
||||||
@ -193,8 +193,8 @@ func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_FOO", "derp")
|
_ = os.Setenv("APP_FOO", "derp")
|
||||||
|
|
||||||
for _, test := range stringFlagTests {
|
for _, test := range stringFlagTests {
|
||||||
flag := &StringFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_FOO"}}
|
fl := &StringFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_FOO"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_FOO]"
|
expectedSuffix := " [$APP_FOO]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -213,22 +213,22 @@ var prefixStringFlagTests = []struct {
|
|||||||
prefixer FlagNamePrefixFunc
|
prefixer FlagNamePrefixFunc
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{"foo", "", "", func(a, b string) string {
|
{"foo", "", "", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
||||||
}, "name: foo, ph: value\t"},
|
}, "name: foo, ph: value\t"},
|
||||||
{"f", "", "", func(a, b string) string {
|
{"f", "", "", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
||||||
}, "name: f, ph: value\t"},
|
}, "name: f, ph: value\t"},
|
||||||
{"f", "The total `foo` desired", "all", func(a, b string) string {
|
{"f", "The total `foo` desired", "all", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
||||||
}, "name: f, ph: foo\tThe total foo desired (default: \"all\")"},
|
}, "name: f, ph: foo\tThe total foo desired (default: \"all\")"},
|
||||||
{"test", "", "Something", func(a, b string) string {
|
{"test", "", "Something", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
||||||
}, "name: test, ph: value\t(default: \"Something\")"},
|
}, "name: test, ph: value\t(default: \"Something\")"},
|
||||||
{"config,c", "Load configuration from `FILE`", "", func(a, b string) string {
|
{"config,c", "Load configuration from `FILE`", "", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
||||||
}, "name: config,c, ph: FILE\tLoad configuration from FILE"},
|
}, "name: config,c, ph: FILE\tLoad configuration from FILE"},
|
||||||
{"config,c", "Load configuration from `CONFIG`", "config.json", func(a, b string) string {
|
{"config,c", "Load configuration from `CONFIG`", "config.json", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
return fmt.Sprintf("name: %s, ph: %s", a, b)
|
||||||
}, "name: config,c, ph: CONFIG\tLoad configuration from CONFIG (default: \"config.json\")"},
|
}, "name: config,c, ph: CONFIG\tLoad configuration from CONFIG (default: \"config.json\")"},
|
||||||
}
|
}
|
||||||
@ -240,8 +240,8 @@ func TestFlagNamePrefixer(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range prefixStringFlagTests {
|
for _, test := range prefixStringFlagTests {
|
||||||
FlagNamePrefixer = test.prefixer
|
FlagNamePrefixer = test.prefixer
|
||||||
flag := StringFlag{Name: test.name, Usage: test.usage, Value: test.value}
|
fl := StringFlag{Name: test.name, Usage: test.usage, Value: test.value}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
}
|
}
|
||||||
@ -252,7 +252,7 @@ func TestStringFlagApply_SetsAllNames(t *testing.T) {
|
|||||||
v := "mmm"
|
v := "mmm"
|
||||||
fl := StringFlag{Name: "hay", Aliases: []string{"H", "hayyy"}, Destination: &v}
|
fl := StringFlag{Name: "hay", Aliases: []string{"H", "hayyy"}, Destination: &v}
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
fl.Apply(set)
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
err := set.Parse([]string{"--hay", "u", "-H", "yuu", "--hayyy", "YUUUU"})
|
err := set.Parse([]string{"--hay", "u", "-H", "yuu", "--hayyy", "YUUUU"})
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
@ -272,9 +272,8 @@ var pathFlagTests = []struct {
|
|||||||
|
|
||||||
func TestPathFlagHelpOutput(t *testing.T) {
|
func TestPathFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range pathFlagTests {
|
for _, test := range pathFlagTests {
|
||||||
flag := &PathFlag{Name: test.name, Aliases: test.aliases, Usage: test.usage, Value: test.value}
|
fl := &PathFlag{Name: test.name, Aliases: test.aliases, Usage: test.usage, Value: test.value}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
@ -284,10 +283,10 @@ func TestPathFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestPathFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestPathFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_PATH", "/path/to/file")
|
_ = os.Setenv("APP_PATH", "/path/to/file")
|
||||||
for _, test := range pathFlagTests {
|
for _, test := range pathFlagTests {
|
||||||
flag := &PathFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_PATH"}}
|
fl := &PathFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_PATH"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_PATH]"
|
expectedSuffix := " [$APP_PATH]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -303,7 +302,7 @@ func TestPathFlagApply_SetsAllNames(t *testing.T) {
|
|||||||
v := "mmm"
|
v := "mmm"
|
||||||
fl := PathFlag{Name: "path", Aliases: []string{"p", "PATH"}, Destination: &v}
|
fl := PathFlag{Name: "path", Aliases: []string{"p", "PATH"}, Destination: &v}
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
fl.Apply(set)
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
err := set.Parse([]string{"--path", "/path/to/file/path", "-p", "/path/to/file/p", "--PATH", "/path/to/file/PATH"})
|
err := set.Parse([]string{"--path", "/path/to/file/path", "-p", "/path/to/file/p", "--PATH", "/path/to/file/PATH"})
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
@ -316,16 +315,16 @@ var envHintFlagTests = []struct {
|
|||||||
hinter FlagEnvHintFunc
|
hinter FlagEnvHintFunc
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{"foo", "", func(a, b string) string {
|
{"foo", "", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("env: %s, str: %s", a, b)
|
return fmt.Sprintf("env: %s, str: %s", a, b)
|
||||||
}, "env: , str: --foo value\t"},
|
}, "env: , str: --foo value\t"},
|
||||||
{"f", "", func(a, b string) string {
|
{"f", "", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("env: %s, str: %s", a, b)
|
return fmt.Sprintf("env: %s, str: %s", a, b)
|
||||||
}, "env: , str: -f value\t"},
|
}, "env: , str: -f value\t"},
|
||||||
{"foo", "ENV_VAR", func(a, b string) string {
|
{"foo", "ENV_VAR", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("env: %s, str: %s", a, b)
|
return fmt.Sprintf("env: %s, str: %s", a, b)
|
||||||
}, "env: ENV_VAR, str: --foo value\t"},
|
}, "env: ENV_VAR, str: --foo value\t"},
|
||||||
{"f", "ENV_VAR", func(a, b string) string {
|
{"f", "ENV_VAR", func(a []string, b string) string {
|
||||||
return fmt.Sprintf("env: %s, str: %s", a, b)
|
return fmt.Sprintf("env: %s, str: %s", a, b)
|
||||||
}, "env: ENV_VAR, str: -f value\t"},
|
}, "env: ENV_VAR, str: -f value\t"},
|
||||||
}
|
}
|
||||||
@ -337,8 +336,8 @@ func TestFlagEnvHinter(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range envHintFlagTests {
|
for _, test := range envHintFlagTests {
|
||||||
FlagEnvHinter = test.hinter
|
FlagEnvHinter = test.hinter
|
||||||
flag := StringFlag{Name: test.name, EnvVar: test.env}
|
fl := StringFlag{Name: test.name, EnvVars: []string{test.env}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
}
|
}
|
||||||
@ -357,13 +356,12 @@ var stringSliceFlagTests = []struct {
|
|||||||
{"f", nil, NewStringSlice("Lipstick"), "-f value\t(default: \"Lipstick\")"},
|
{"f", nil, NewStringSlice("Lipstick"), "-f value\t(default: \"Lipstick\")"},
|
||||||
{"test", nil, NewStringSlice("Something"), "--test value\t(default: \"Something\")"},
|
{"test", nil, NewStringSlice("Something"), "--test value\t(default: \"Something\")"},
|
||||||
{"dee", []string{"d"}, NewStringSlice("Inka", "Dinka", "dooo"), "--dee value, -d value\t(default: \"Inka\", \"Dinka\", \"dooo\")"},
|
{"dee", []string{"d"}, NewStringSlice("Inka", "Dinka", "dooo"), "--dee value, -d value\t(default: \"Inka\", \"Dinka\", \"dooo\")"},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringSliceFlagHelpOutput(t *testing.T) {
|
func TestStringSliceFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range stringSliceFlagTests {
|
for _, test := range stringSliceFlagTests {
|
||||||
flag := &StringSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value}
|
f := &StringSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value}
|
||||||
output := flag.String()
|
output := f.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
@ -376,8 +374,8 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_QWWX", "11,4")
|
_ = os.Setenv("APP_QWWX", "11,4")
|
||||||
|
|
||||||
for _, test := range stringSliceFlagTests {
|
for _, test := range stringSliceFlagTests {
|
||||||
flag := &StringSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_QWWX"}}
|
fl := &StringSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_QWWX"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_QWWX]"
|
expectedSuffix := " [$APP_QWWX]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -392,7 +390,7 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
func TestStringSliceFlagApply_SetsAllNames(t *testing.T) {
|
func TestStringSliceFlagApply_SetsAllNames(t *testing.T) {
|
||||||
fl := StringSliceFlag{Name: "goat", Aliases: []string{"G", "gooots"}}
|
fl := StringSliceFlag{Name: "goat", Aliases: []string{"G", "gooots"}}
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
fl.Apply(set)
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
err := set.Parse([]string{"--goat", "aaa", "-G", "bbb", "--gooots", "eeeee"})
|
err := set.Parse([]string{"--goat", "aaa", "-G", "bbb", "--gooots", "eeeee"})
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
@ -408,8 +406,8 @@ var intFlagTests = []struct {
|
|||||||
|
|
||||||
func TestIntFlagHelpOutput(t *testing.T) {
|
func TestIntFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range intFlagTests {
|
for _, test := range intFlagTests {
|
||||||
flag := &IntFlag{Name: test.name, Value: 9}
|
fl := &IntFlag{Name: test.name, Value: 9}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%s does not match %s", output, test.expected)
|
t.Errorf("%s does not match %s", output, test.expected)
|
||||||
@ -419,12 +417,11 @@ func TestIntFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_BAR", "2")
|
|
||||||
_ = os.Setenv("APP_BAR", "2")
|
_ = os.Setenv("APP_BAR", "2")
|
||||||
|
|
||||||
for _, test := range intFlagTests {
|
for _, test := range intFlagTests {
|
||||||
flag := &IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
fl := &IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_BAR]"
|
expectedSuffix := " [$APP_BAR]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -440,7 +437,7 @@ func TestIntFlagApply_SetsAllNames(t *testing.T) {
|
|||||||
v := 3
|
v := 3
|
||||||
fl := IntFlag{Name: "banana", Aliases: []string{"B", "banannanana"}, Destination: &v}
|
fl := IntFlag{Name: "banana", Aliases: []string{"B", "banannanana"}, Destination: &v}
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
fl.Apply(set)
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
err := set.Parse([]string{"--banana", "1", "-B", "2", "--banannanana", "5"})
|
err := set.Parse([]string{"--banana", "1", "-B", "2", "--banannanana", "5"})
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
@ -457,8 +454,8 @@ var int64FlagTests = []struct {
|
|||||||
|
|
||||||
func TestInt64FlagHelpOutput(t *testing.T) {
|
func TestInt64FlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range int64FlagTests {
|
for _, test := range int64FlagTests {
|
||||||
flag := Int64Flag{Name: test.name, Value: 8589934592}
|
fl := Int64Flag{Name: test.name, Value: 8589934592}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%s does not match %s", output, test.expected)
|
t.Errorf("%s does not match %s", output, test.expected)
|
||||||
@ -471,8 +468,8 @@ func TestInt64FlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_BAR", "2")
|
_ = os.Setenv("APP_BAR", "2")
|
||||||
|
|
||||||
for _, test := range int64FlagTests {
|
for _, test := range int64FlagTests {
|
||||||
flag := IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
fl := IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_BAR]"
|
expectedSuffix := " [$APP_BAR]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -494,8 +491,8 @@ var uintFlagTests = []struct {
|
|||||||
|
|
||||||
func TestUintFlagHelpOutput(t *testing.T) {
|
func TestUintFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range uintFlagTests {
|
for _, test := range uintFlagTests {
|
||||||
flag := UintFlag{Name: test.name, Value: 41}
|
fl := UintFlag{Name: test.name, Value: 41}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%s does not match %s", output, test.expected)
|
t.Errorf("%s does not match %s", output, test.expected)
|
||||||
@ -508,8 +505,8 @@ func TestUintFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_BAR", "2")
|
_ = os.Setenv("APP_BAR", "2")
|
||||||
|
|
||||||
for _, test := range uintFlagTests {
|
for _, test := range uintFlagTests {
|
||||||
flag := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
fl := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_BAR]"
|
expectedSuffix := " [$APP_BAR]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -531,8 +528,8 @@ var uint64FlagTests = []struct {
|
|||||||
|
|
||||||
func TestUint64FlagHelpOutput(t *testing.T) {
|
func TestUint64FlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range uint64FlagTests {
|
for _, test := range uint64FlagTests {
|
||||||
flag := Uint64Flag{Name: test.name, Value: 8589934582}
|
fl := Uint64Flag{Name: test.name, Value: 8589934582}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%s does not match %s", output, test.expected)
|
t.Errorf("%s does not match %s", output, test.expected)
|
||||||
@ -545,8 +542,8 @@ func TestUint64FlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_BAR", "2")
|
_ = os.Setenv("APP_BAR", "2")
|
||||||
|
|
||||||
for _, test := range uint64FlagTests {
|
for _, test := range uint64FlagTests {
|
||||||
flag := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
fl := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_BAR]"
|
expectedSuffix := " [$APP_BAR]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -568,8 +565,8 @@ var durationFlagTests = []struct {
|
|||||||
|
|
||||||
func TestDurationFlagHelpOutput(t *testing.T) {
|
func TestDurationFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range durationFlagTests {
|
for _, test := range durationFlagTests {
|
||||||
flag := &DurationFlag{Name: test.name, Value: 1 * time.Second}
|
fl := &DurationFlag{Name: test.name, Value: 1 * time.Second}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
@ -582,8 +579,8 @@ func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_BAR", "2h3m6s")
|
_ = os.Setenv("APP_BAR", "2h3m6s")
|
||||||
|
|
||||||
for _, test := range durationFlagTests {
|
for _, test := range durationFlagTests {
|
||||||
flag := &DurationFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
fl := &DurationFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_BAR]"
|
expectedSuffix := " [$APP_BAR]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -599,7 +596,7 @@ func TestDurationFlagApply_SetsAllNames(t *testing.T) {
|
|||||||
v := time.Second * 20
|
v := time.Second * 20
|
||||||
fl := DurationFlag{Name: "howmuch", Aliases: []string{"H", "whyyy"}, Destination: &v}
|
fl := DurationFlag{Name: "howmuch", Aliases: []string{"H", "whyyy"}, Destination: &v}
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
fl.Apply(set)
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
err := set.Parse([]string{"--howmuch", "30s", "-H", "5m", "--whyyy", "30h"})
|
err := set.Parse([]string{"--howmuch", "30s", "-H", "5m", "--whyyy", "30h"})
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
@ -619,8 +616,8 @@ var intSliceFlagTests = []struct {
|
|||||||
|
|
||||||
func TestIntSliceFlagHelpOutput(t *testing.T) {
|
func TestIntSliceFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range intSliceFlagTests {
|
for _, test := range intSliceFlagTests {
|
||||||
flag := &IntSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value}
|
fl := &IntSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
@ -633,8 +630,8 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_SMURF", "42,3")
|
_ = os.Setenv("APP_SMURF", "42,3")
|
||||||
|
|
||||||
for _, test := range intSliceFlagTests {
|
for _, test := range intSliceFlagTests {
|
||||||
flag := &IntSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
fl := &IntSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_SMURF]"
|
expectedSuffix := " [$APP_SMURF]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -649,7 +646,7 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
func TestIntSliceFlagApply_SetsAllNames(t *testing.T) {
|
func TestIntSliceFlagApply_SetsAllNames(t *testing.T) {
|
||||||
fl := IntSliceFlag{Name: "bits", Aliases: []string{"B", "bips"}}
|
fl := IntSliceFlag{Name: "bits", Aliases: []string{"B", "bips"}}
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
fl.Apply(set)
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
err := set.Parse([]string{"--bits", "23", "-B", "3", "--bips", "99"})
|
err := set.Parse([]string{"--bits", "23", "-B", "3", "--bips", "99"})
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
@ -669,8 +666,8 @@ var int64SliceFlagTests = []struct {
|
|||||||
|
|
||||||
func TestInt64SliceFlagHelpOutput(t *testing.T) {
|
func TestInt64SliceFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range int64SliceFlagTests {
|
for _, test := range int64SliceFlagTests {
|
||||||
flag := Int64SliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value}
|
fl := Int64SliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
@ -683,8 +680,8 @@ func TestInt64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_SMURF", "42,17179869184")
|
_ = os.Setenv("APP_SMURF", "42,17179869184")
|
||||||
|
|
||||||
for _, test := range int64SliceFlagTests {
|
for _, test := range int64SliceFlagTests {
|
||||||
flag := Int64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
fl := Int64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_SMURF]"
|
expectedSuffix := " [$APP_SMURF]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -720,8 +717,8 @@ func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_BAZ", "99.4")
|
_ = os.Setenv("APP_BAZ", "99.4")
|
||||||
|
|
||||||
for _, test := range float64FlagTests {
|
for _, test := range float64FlagTests {
|
||||||
flag := &Float64Flag{Name: test.name, EnvVars: []string{"APP_BAZ"}}
|
fl := &Float64Flag{Name: test.name, EnvVars: []string{"APP_BAZ"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_BAZ]"
|
expectedSuffix := " [$APP_BAZ]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -737,7 +734,7 @@ func TestFloat64FlagApply_SetsAllNames(t *testing.T) {
|
|||||||
v := 99.1
|
v := 99.1
|
||||||
fl := Float64Flag{Name: "noodles", Aliases: []string{"N", "nurbles"}, Destination: &v}
|
fl := Float64Flag{Name: "noodles", Aliases: []string{"N", "nurbles"}, Destination: &v}
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
fl.Apply(set)
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
err := set.Parse([]string{"--noodles", "1.3", "-N", "11", "--nurbles", "43.33333"})
|
err := set.Parse([]string{"--noodles", "1.3", "-N", "11", "--nurbles", "43.33333"})
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
@ -752,14 +749,14 @@ var float64SliceFlagTests = []struct {
|
|||||||
}{
|
}{
|
||||||
{"heads", nil, NewFloat64Slice(), "--heads value\t"},
|
{"heads", nil, NewFloat64Slice(), "--heads value\t"},
|
||||||
{"H", nil, NewFloat64Slice(), "-H value\t"},
|
{"H", nil, NewFloat64Slice(), "-H value\t"},
|
||||||
{"heads", []string{"H"}, NewFloat64Slice(float64(0.1234), float64(-10.5)),
|
{"heads", []string{"H"}, NewFloat64Slice(0.1234, -10.5),
|
||||||
"--heads value, -H value\t(default: 0.1234, -10.5)"},
|
"--heads value, -H value\t(default: 0.1234, -10.5)"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloat64SliceFlagHelpOutput(t *testing.T) {
|
func TestFloat64SliceFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range float64SliceFlagTests {
|
for _, test := range float64SliceFlagTests {
|
||||||
flag := Float64SliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value}
|
fl := Float64SliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
@ -769,10 +766,10 @@ func TestFloat64SliceFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestFloat64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestFloat64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_SMURF", "0.1234,-10.5")
|
_ = os.Setenv("APP_SMURF", "0.1234,-10.5")
|
||||||
for _, test := range float64SliceFlagTests {
|
for _, test := range float64SliceFlagTests {
|
||||||
flag := Float64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
fl := Float64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_SMURF]"
|
expectedSuffix := " [$APP_SMURF]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -795,8 +792,8 @@ var genericFlagTests = []struct {
|
|||||||
|
|
||||||
func TestGenericFlagHelpOutput(t *testing.T) {
|
func TestGenericFlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range genericFlagTests {
|
for _, test := range genericFlagTests {
|
||||||
flag := &GenericFlag{Name: test.name, Value: test.value, Usage: "test flag"}
|
fl := &GenericFlag{Name: test.name, Value: test.value, Usage: "test fl"}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("%q does not match %q", output, test.expected)
|
t.Errorf("%q does not match %q", output, test.expected)
|
||||||
@ -809,8 +806,8 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_ZAP", "3")
|
_ = os.Setenv("APP_ZAP", "3")
|
||||||
|
|
||||||
for _, test := range genericFlagTests {
|
for _, test := range genericFlagTests {
|
||||||
flag := &GenericFlag{Name: test.name, EnvVars: []string{"APP_ZAP"}}
|
fl := &GenericFlag{Name: test.name, EnvVars: []string{"APP_ZAP"}}
|
||||||
output := flag.String()
|
output := fl.String()
|
||||||
|
|
||||||
expectedSuffix := " [$APP_ZAP]"
|
expectedSuffix := " [$APP_ZAP]"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -825,7 +822,7 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
func TestGenericFlagApply_SetsAllNames(t *testing.T) {
|
func TestGenericFlagApply_SetsAllNames(t *testing.T) {
|
||||||
fl := GenericFlag{Name: "orbs", Aliases: []string{"O", "obrs"}, Value: &Parser{}}
|
fl := GenericFlag{Name: "orbs", Aliases: []string{"O", "obrs"}, Value: &Parser{}}
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
fl.Apply(set)
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
err := set.Parse([]string{"--orbs", "eleventy,3", "-O", "4,bloop", "--obrs", "19,s"})
|
err := set.Parse([]string{"--orbs", "eleventy,3", "-O", "4,bloop", "--obrs", "19,s"})
|
||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
@ -1424,8 +1421,8 @@ func TestParseBoolShortOptionHandle(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolFlag{Name: "serve, s"},
|
&BoolFlag{Name: "serve", Aliases: []string{"s"}},
|
||||||
BoolFlag{Name: "option, o"},
|
&BoolFlag{Name: "option", Aliases: []string{"o"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1471,7 +1468,7 @@ func TestParseMultiBoolFromEnv(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseMultiBoolFromEnvCascade(t *testing.T) {
|
func TestParseMultiBoolFromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_DEBUG", "1")
|
_ = os.Setenv("APP_DEBUG", "1")
|
||||||
_ = (&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
&BoolFlag{Name: "debug", Aliases: []string{"d"}, EnvVars: []string{"COMPAT_DEBUG", "APP_DEBUG"}},
|
&BoolFlag{Name: "debug", Aliases: []string{"d"}, EnvVars: []string{"COMPAT_DEBUG", "APP_DEBUG"}},
|
||||||
@ -1504,7 +1501,7 @@ func TestParseBoolTFromEnv(t *testing.T) {
|
|||||||
_ = os.Setenv("DEBUG", test.input)
|
_ = os.Setenv("DEBUG", test.input)
|
||||||
_ = (&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolTFlag{Name: "debug, d", EnvVar: "DEBUG"},
|
&BoolFlag{Name: "debug", Aliases: []string{"d"}, Value: true, EnvVars: []string{"DEBUG"}},
|
||||||
},
|
},
|
||||||
Action: func(ctx *Context) error {
|
Action: func(ctx *Context) error {
|
||||||
if ctx.Bool("debug") != test.output {
|
if ctx.Bool("debug") != test.output {
|
||||||
@ -1541,13 +1538,13 @@ func TestParseMultiBoolTFromEnv(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_DEBUG", "0")
|
_ = os.Setenv("APP_DEBUG", "0")
|
||||||
_ = (&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
&BoolTFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
&BoolFlag{Name: "debug", Aliases: []string{"d"}, Value: true, EnvVars: []string{"DEBUG"}},
|
||||||
},
|
},
|
||||||
Action: func(ctx *Context) error {
|
Action: func(ctx *Context) error {
|
||||||
if ctx.BoolT("debug") != false {
|
if ctx.Bool("debug") != false {
|
||||||
t.Errorf("main name not set from env")
|
t.Errorf("main name not set from env")
|
||||||
}
|
}
|
||||||
if ctx.BoolT("d") != false {
|
if ctx.Bool("d") != false {
|
||||||
t.Errorf("short name not set from env")
|
t.Errorf("short name not set from env")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -1560,13 +1557,13 @@ func TestParseMultiBoolTFromEnvCascade(t *testing.T) {
|
|||||||
_ = os.Setenv("APP_DEBUG", "0")
|
_ = os.Setenv("APP_DEBUG", "0")
|
||||||
_ = (&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
&BoolTFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
&BoolFlag{Name: "debug", Aliases: []string{"d"}, Value: true, EnvVars: []string{"DEBUG"}},
|
||||||
},
|
},
|
||||||
Action: func(ctx *Context) error {
|
Action: func(ctx *Context) error {
|
||||||
if ctx.BoolT("debug") != false {
|
if ctx.Bool("debug") != false {
|
||||||
t.Errorf("main name not set from env")
|
t.Errorf("main name not set from env")
|
||||||
}
|
}
|
||||||
if ctx.BoolT("d") != false {
|
if ctx.Bool("d") != false {
|
||||||
t.Errorf("short name not set from env")
|
t.Errorf("short name not set from env")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -1675,14 +1672,14 @@ func TestFlagFromFile(t *testing.T) {
|
|||||||
|
|
||||||
var filePathTests = []struct {
|
var filePathTests = []struct {
|
||||||
path string
|
path string
|
||||||
name string
|
name []string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{"file-does-not-exist", "APP_BAR", ""},
|
{"file-does-not-exist", []string{"APP_BAR"}, ""},
|
||||||
{"file-does-not-exist", "APP_FOO", "123"},
|
{"file-does-not-exist", []string{"APP_FOO"}, "123"},
|
||||||
{"file-does-not-exist", "APP_FOO,APP_BAR", "123"},
|
{"file-does-not-exist", []string{"APP_FOO", "APP_BAR"}, "123"},
|
||||||
{temp.Name(), "APP_FOO", "123"},
|
{temp.Name(), []string{"APP_FOO"}, "123"},
|
||||||
{temp.Name(), "APP_BAR", "abc"},
|
{temp.Name(), []string{"APP_BAR"}, "abc"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, filePathTest := range filePathTests {
|
for _, filePathTest := range filePathTests {
|
||||||
@ -1702,7 +1699,7 @@ func TestStringSlice_Serialized_Set(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sl1 := NewStringSlice("c", "d")
|
sl1 := NewStringSlice("c", "d")
|
||||||
sl1.Set(ser0)
|
_ = sl1.Set(ser0)
|
||||||
|
|
||||||
if sl0.String() != sl1.String() {
|
if sl0.String() != sl1.String() {
|
||||||
t.Fatalf("pre and post serialization do not match: %v != %v", sl0, sl1)
|
t.Fatalf("pre and post serialization do not match: %v != %v", sl0, sl1)
|
||||||
@ -1718,7 +1715,7 @@ func TestIntSlice_Serialized_Set(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sl1 := NewIntSlice(3, 4)
|
sl1 := NewIntSlice(3, 4)
|
||||||
sl1.Set(ser0)
|
_ = sl1.Set(ser0)
|
||||||
|
|
||||||
if sl0.String() != sl1.String() {
|
if sl0.String() != sl1.String() {
|
||||||
t.Fatalf("pre and post serialization do not match: %v != %v", sl0, sl1)
|
t.Fatalf("pre and post serialization do not match: %v != %v", sl0, sl1)
|
||||||
@ -1734,7 +1731,7 @@ func TestInt64Slice_Serialized_Set(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sl1 := NewInt64Slice(int64(3), int64(4))
|
sl1 := NewInt64Slice(int64(3), int64(4))
|
||||||
sl1.Set(ser0)
|
_ = sl1.Set(ser0)
|
||||||
|
|
||||||
if sl0.String() != sl1.String() {
|
if sl0.String() != sl1.String() {
|
||||||
t.Fatalf("pre and post serialization do not match: %v != %v", sl0, sl1)
|
t.Fatalf("pre and post serialization do not match: %v != %v", sl0, sl1)
|
||||||
|
@ -79,7 +79,10 @@ func (f *UintFlag) GetValue() string {
|
|||||||
// Uint looks up the value of a local UintFlag, returns
|
// Uint looks up the value of a local UintFlag, returns
|
||||||
// 0 if not found
|
// 0 if not found
|
||||||
func (c *Context) Uint(name string) uint {
|
func (c *Context) Uint(name string) uint {
|
||||||
return lookupUint(name, c.flagSet)
|
if fs := lookupFlagSet(name, c); fs != nil {
|
||||||
|
return lookupUint(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlobalUint looks up the value of a global UintFlag, returns
|
// GlobalUint looks up the value of a global UintFlag, returns
|
||||||
|
@ -79,7 +79,10 @@ func (f *Uint64Flag) GetValue() string {
|
|||||||
// Uint64 looks up the value of a local Uint64Flag, returns
|
// Uint64 looks up the value of a local Uint64Flag, returns
|
||||||
// 0 if not found
|
// 0 if not found
|
||||||
func (c *Context) Uint64(name string) uint64 {
|
func (c *Context) Uint64(name string) uint64 {
|
||||||
return lookupUint64(name, c.flagSet)
|
if fs := lookupFlagSet(name, c); fs != nil {
|
||||||
|
return lookupUint64(name, fs)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlobalUint64 looks up the value of a global Uint64Flag, returns
|
// GlobalUint64 looks up the value of a global Uint64Flag, returns
|
||||||
|
2
funcs.go
2
funcs.go
@ -23,7 +23,7 @@ type CommandNotFoundFunc func(*Context, string)
|
|||||||
// is displayed and the execution is interrupted.
|
// is displayed and the execution is interrupted.
|
||||||
type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error
|
type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error
|
||||||
|
|
||||||
// ExitErrHandlerFunc is executed if provided in order to handle ExitError values
|
// ExitErrHandlerFunc is executed if provided in order to handle exitError values
|
||||||
// returned by Actions and Before/After functions.
|
// returned by Actions and Before/After functions.
|
||||||
type ExitErrHandlerFunc func(context *Context, err error)
|
type ExitErrHandlerFunc func(context *Context, err error)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user