linter fixes
code cleanup changing some test code to ensure uniformity
This commit is contained in:
parent
521735b760
commit
fdba7e0f8c
@ -72,7 +72,7 @@ func (f *GenericFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourc
|
|||||||
}
|
}
|
||||||
if value != nil {
|
if value != nil {
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
f.set.Set(f.Name, value.String())
|
_ = f.set.Set(f.Name, value.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ func (f *BoolFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceCo
|
|||||||
}
|
}
|
||||||
if value {
|
if value {
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
f.set.Set(f.Name, strconv.FormatBool(value))
|
_ = f.set.Set(f.Name, strconv.FormatBool(value))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ func (f *BoolTFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceC
|
|||||||
}
|
}
|
||||||
if !value {
|
if !value {
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
f.set.Set(f.Name, strconv.FormatBool(value))
|
_ = f.set.Set(f.Name, strconv.FormatBool(value))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ func (f *StringFlag) ApplyInputSourceValue(context *cli.Context, isc InputSource
|
|||||||
}
|
}
|
||||||
if value != "" {
|
if value != "" {
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
f.set.Set(f.Name, value)
|
_ = f.set.Set(f.Name, value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ func (f *IntFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceCon
|
|||||||
}
|
}
|
||||||
if value > 0 {
|
if value > 0 {
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
f.set.Set(f.Name, strconv.FormatInt(int64(value), 10))
|
_ = f.set.Set(f.Name, strconv.FormatInt(int64(value), 10))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ func (f *DurationFlag) ApplyInputSourceValue(context *cli.Context, isc InputSour
|
|||||||
}
|
}
|
||||||
if value > 0 {
|
if value > 0 {
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
f.set.Set(f.Name, value.String())
|
_ = f.set.Set(f.Name, value.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ func (f *Float64Flag) ApplyInputSourceValue(context *cli.Context, isc InputSourc
|
|||||||
if value > 0 {
|
if value > 0 {
|
||||||
floatStr := float64ToString(value)
|
floatStr := float64ToString(value)
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
f.set.Set(f.Name, floatStr)
|
_ = f.set.Set(f.Name, floatStr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,30 +239,30 @@ func TestDurationApplyInputSourceMethodSet(t *testing.T) {
|
|||||||
c := runTest(t, testApplyInputSource{
|
c := runTest(t, testApplyInputSource{
|
||||||
Flag: NewDurationFlag(cli.DurationFlag{Name: "test"}),
|
Flag: NewDurationFlag(cli.DurationFlag{Name: "test"}),
|
||||||
FlagName: "test",
|
FlagName: "test",
|
||||||
MapValue: time.Duration(30 * time.Second),
|
MapValue: 30 * time.Second,
|
||||||
})
|
})
|
||||||
expect(t, time.Duration(30*time.Second), c.Duration("test"))
|
expect(t, 30*time.Second, c.Duration("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDurationApplyInputSourceMethodContextSet(t *testing.T) {
|
func TestDurationApplyInputSourceMethodContextSet(t *testing.T) {
|
||||||
c := runTest(t, testApplyInputSource{
|
c := runTest(t, testApplyInputSource{
|
||||||
Flag: NewDurationFlag(cli.DurationFlag{Name: "test"}),
|
Flag: NewDurationFlag(cli.DurationFlag{Name: "test"}),
|
||||||
FlagName: "test",
|
FlagName: "test",
|
||||||
MapValue: time.Duration(30 * time.Second),
|
MapValue: 30 * time.Second,
|
||||||
ContextValueString: time.Duration(15 * time.Second).String(),
|
ContextValueString: (15 * time.Second).String(),
|
||||||
})
|
})
|
||||||
expect(t, time.Duration(15*time.Second), c.Duration("test"))
|
expect(t, 15*time.Second, c.Duration("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDurationApplyInputSourceMethodEnvVarSet(t *testing.T) {
|
func TestDurationApplyInputSourceMethodEnvVarSet(t *testing.T) {
|
||||||
c := runTest(t, testApplyInputSource{
|
c := runTest(t, testApplyInputSource{
|
||||||
Flag: NewDurationFlag(cli.DurationFlag{Name: "test", EnvVar: "TEST"}),
|
Flag: NewDurationFlag(cli.DurationFlag{Name: "test", EnvVar: "TEST"}),
|
||||||
FlagName: "test",
|
FlagName: "test",
|
||||||
MapValue: time.Duration(30 * time.Second),
|
MapValue: 30 * time.Second,
|
||||||
EnvVarName: "TEST",
|
EnvVarName: "TEST",
|
||||||
EnvVarValue: time.Duration(15 * time.Second).String(),
|
EnvVarValue: (15 * time.Second).String(),
|
||||||
})
|
})
|
||||||
expect(t, time.Duration(15*time.Second), c.Duration("test"))
|
expect(t, 15*time.Second, c.Duration("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloat64ApplyInputSourceMethodSet(t *testing.T) {
|
func TestFloat64ApplyInputSourceMethodSet(t *testing.T) {
|
||||||
@ -300,19 +300,19 @@ func runTest(t *testing.T, test testApplyInputSource) *cli.Context {
|
|||||||
set := flag.NewFlagSet(test.FlagSetName, flag.ContinueOnError)
|
set := flag.NewFlagSet(test.FlagSetName, flag.ContinueOnError)
|
||||||
c := cli.NewContext(nil, set, nil)
|
c := cli.NewContext(nil, set, nil)
|
||||||
if test.EnvVarName != "" && test.EnvVarValue != "" {
|
if test.EnvVarName != "" && test.EnvVarValue != "" {
|
||||||
os.Setenv(test.EnvVarName, test.EnvVarValue)
|
_ = os.Setenv(test.EnvVarName, test.EnvVarValue)
|
||||||
defer os.Setenv(test.EnvVarName, "")
|
defer os.Setenv(test.EnvVarName, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
test.Flag.Apply(set)
|
test.Flag.Apply(set)
|
||||||
if test.ContextValue != nil {
|
if test.ContextValue != nil {
|
||||||
flag := set.Lookup(test.FlagName)
|
f := set.Lookup(test.FlagName)
|
||||||
flag.Value = test.ContextValue
|
f.Value = test.ContextValue
|
||||||
}
|
}
|
||||||
if test.ContextValueString != "" {
|
if test.ContextValueString != "" {
|
||||||
set.Set(test.FlagName, test.ContextValueString)
|
_ = set.Set(test.FlagName, test.ContextValueString)
|
||||||
}
|
}
|
||||||
test.Flag.ApplyInputSourceValue(c, inputSource)
|
_ = test.Flag.ApplyInputSourceValue(c, inputSource)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ func TestCommandJSONFileTest(t *testing.T) {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
test := []string{"test-cmd", "--load", fileName}
|
test := []string{"test-cmd", "--load", fileName}
|
||||||
set.Parse(test)
|
_ = set.Parse(test)
|
||||||
|
|
||||||
c := cli.NewContext(app, set, nil)
|
c := cli.NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -52,11 +52,11 @@ func TestCommandJSONFileTestGlobalEnvVarWins(t *testing.T) {
|
|||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
os.Setenv("THE_TEST", "10")
|
_ = os.Setenv("THE_TEST", "10")
|
||||||
defer os.Setenv("THE_TEST", "")
|
defer os.Setenv("THE_TEST", "")
|
||||||
|
|
||||||
test := []string{"test-cmd", "--load", fileName}
|
test := []string{"test-cmd", "--load", fileName}
|
||||||
set.Parse(test)
|
_ = set.Parse(test)
|
||||||
|
|
||||||
c := cli.NewContext(app, set, nil)
|
c := cli.NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -87,11 +87,11 @@ func TestCommandJSONFileTestGlobalEnvVarWinsNested(t *testing.T) {
|
|||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
os.Setenv("THE_TEST", "10")
|
_ = os.Setenv("THE_TEST", "10")
|
||||||
defer os.Setenv("THE_TEST", "")
|
defer os.Setenv("THE_TEST", "")
|
||||||
|
|
||||||
test := []string{"test-cmd", "--load", fileName}
|
test := []string{"test-cmd", "--load", fileName}
|
||||||
set.Parse(test)
|
_ = set.Parse(test)
|
||||||
|
|
||||||
c := cli.NewContext(app, set, nil)
|
c := cli.NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ func TestCommandJSONFileTestSpecifiedFlagWins(t *testing.T) {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
test := []string{"test-cmd", "--load", fileName, "--test", "7"}
|
test := []string{"test-cmd", "--load", fileName, "--test", "7"}
|
||||||
set.Parse(test)
|
_ = set.Parse(test)
|
||||||
|
|
||||||
c := cli.NewContext(app, set, nil)
|
c := cli.NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ func TestCommandJSONFileTestSpecifiedFlagWinsNested(t *testing.T) {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
test := []string{"test-cmd", "--load", fileName, "--top.test", "7"}
|
test := []string{"test-cmd", "--load", fileName, "--top.test", "7"}
|
||||||
set.Parse(test)
|
_ = set.Parse(test)
|
||||||
|
|
||||||
c := cli.NewContext(app, set, nil)
|
c := cli.NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ func TestCommandJSONFileTestDefaultValueFileWins(t *testing.T) {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
test := []string{"test-cmd", "--load", fileName}
|
test := []string{"test-cmd", "--load", fileName}
|
||||||
set.Parse(test)
|
_ = set.Parse(test)
|
||||||
|
|
||||||
c := cli.NewContext(app, set, nil)
|
c := cli.NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ func TestCommandJSONFileTestDefaultValueFileWinsNested(t *testing.T) {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
test := []string{"test-cmd", "--load", fileName}
|
test := []string{"test-cmd", "--load", fileName}
|
||||||
set.Parse(test)
|
_ = set.Parse(test)
|
||||||
|
|
||||||
c := cli.NewContext(app, set, nil)
|
c := cli.NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -250,11 +250,11 @@ func TestCommandJSONFileFlagHasDefaultGlobalEnvJSONSetGlobalEnvWins(t *testing.T
|
|||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
os.Setenv("THE_TEST", "11")
|
_ = os.Setenv("THE_TEST", "11")
|
||||||
defer os.Setenv("THE_TEST", "")
|
defer os.Setenv("THE_TEST", "")
|
||||||
|
|
||||||
test := []string{"test-cmd", "--load", fileName}
|
test := []string{"test-cmd", "--load", fileName}
|
||||||
set.Parse(test)
|
_ = set.Parse(test)
|
||||||
|
|
||||||
c := cli.NewContext(app, set, nil)
|
c := cli.NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -284,11 +284,11 @@ func TestCommandJSONFileFlagHasDefaultGlobalEnvJSONSetGlobalEnvWinsNested(t *tes
|
|||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
os.Setenv("THE_TEST", "11")
|
_ = os.Setenv("THE_TEST", "11")
|
||||||
defer os.Setenv("THE_TEST", "")
|
defer os.Setenv("THE_TEST", "")
|
||||||
|
|
||||||
test := []string{"test-cmd", "--load", fileName}
|
test := []string{"test-cmd", "--load", fileName}
|
||||||
set.Parse(test)
|
_ = set.Parse(test)
|
||||||
|
|
||||||
c := cli.NewContext(app, set, nil)
|
c := cli.NewContext(app, set, nil)
|
||||||
|
|
||||||
|
43
app.go
43
app.go
@ -11,9 +11,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md"
|
changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md"
|
||||||
appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL)
|
appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL)
|
||||||
runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL)
|
// unused variable. commented for now. will remove in future if agreed upon by everyone
|
||||||
|
//runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL)
|
||||||
|
|
||||||
contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you."
|
contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you."
|
||||||
|
|
||||||
@ -138,7 +139,7 @@ func (a *App) Setup() {
|
|||||||
a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email})
|
a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email})
|
||||||
}
|
}
|
||||||
|
|
||||||
newCmds := []Command{}
|
var newCmds []Command
|
||||||
for _, c := range a.Commands {
|
for _, c := range a.Commands {
|
||||||
if c.HelpName == "" {
|
if c.HelpName == "" {
|
||||||
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
|
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
|
||||||
@ -197,8 +198,8 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
nerr := normalizeFlags(a.Flags, set)
|
nerr := normalizeFlags(a.Flags, set)
|
||||||
context := NewContext(a, set, nil)
|
context := NewContext(a, set, nil)
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
fmt.Fprintln(a.Writer, nerr)
|
_, _ = fmt.Fprintln(a.Writer, nerr)
|
||||||
ShowAppHelp(context)
|
_ = ShowAppHelp(context)
|
||||||
return nerr
|
return nerr
|
||||||
}
|
}
|
||||||
context.shellComplete = shellComplete
|
context.shellComplete = shellComplete
|
||||||
@ -213,13 +214,13 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
a.handleExitCoder(context, err)
|
a.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
_, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
||||||
ShowAppHelp(context)
|
_ = ShowAppHelp(context)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !a.HideHelp && checkHelp(context) {
|
if !a.HideHelp && checkHelp(context) {
|
||||||
ShowAppHelp(context)
|
_ = ShowAppHelp(context)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +231,7 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
|
|
||||||
cerr := checkRequiredFlags(a.Flags, context)
|
cerr := checkRequiredFlags(a.Flags, context)
|
||||||
if cerr != nil {
|
if cerr != nil {
|
||||||
ShowAppHelp(context)
|
_ = ShowAppHelp(context)
|
||||||
return cerr
|
return cerr
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,8 +250,8 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
if a.Before != nil {
|
if a.Before != nil {
|
||||||
beforeErr := a.Before(context)
|
beforeErr := a.Before(context)
|
||||||
if beforeErr != nil {
|
if beforeErr != nil {
|
||||||
fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
|
_, _ = fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
|
||||||
ShowAppHelp(context)
|
_ = ShowAppHelp(context)
|
||||||
a.handleExitCoder(context, beforeErr)
|
a.handleExitCoder(context, beforeErr)
|
||||||
err = beforeErr
|
err = beforeErr
|
||||||
return err
|
return err
|
||||||
@ -284,7 +285,7 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
// code in the cli.ExitCoder
|
// code in the cli.ExitCoder
|
||||||
func (a *App) RunAndExitOnError() {
|
func (a *App) RunAndExitOnError() {
|
||||||
if err := a.Run(os.Args); err != nil {
|
if err := a.Run(os.Args); err != nil {
|
||||||
fmt.Fprintln(a.errWriter(), err)
|
_, _ = fmt.Fprintln(a.errWriter(), err)
|
||||||
OsExiter(1)
|
OsExiter(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,12 +324,12 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
context := NewContext(a, set, ctx)
|
context := NewContext(a, set, ctx)
|
||||||
|
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
fmt.Fprintln(a.Writer, nerr)
|
_, _ = fmt.Fprintln(a.Writer, nerr)
|
||||||
fmt.Fprintln(a.Writer)
|
_, _ = fmt.Fprintln(a.Writer)
|
||||||
if len(a.Commands) > 0 {
|
if len(a.Commands) > 0 {
|
||||||
ShowSubcommandHelp(context)
|
_ = ShowSubcommandHelp(context)
|
||||||
} else {
|
} else {
|
||||||
ShowCommandHelp(ctx, context.Args().First())
|
_ = ShowCommandHelp(ctx, context.Args().First())
|
||||||
}
|
}
|
||||||
return nerr
|
return nerr
|
||||||
}
|
}
|
||||||
@ -343,8 +344,8 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
a.handleExitCoder(context, err)
|
a.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
_, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
||||||
ShowSubcommandHelp(context)
|
_ = ShowSubcommandHelp(context)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +361,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
|
|
||||||
cerr := checkRequiredFlags(a.Flags, context)
|
cerr := checkRequiredFlags(a.Flags, context)
|
||||||
if cerr != nil {
|
if cerr != nil {
|
||||||
ShowSubcommandHelp(context)
|
_ = ShowSubcommandHelp(context)
|
||||||
return cerr
|
return cerr
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +441,7 @@ func (a *App) VisibleCategories() []*CommandCategory {
|
|||||||
|
|
||||||
// VisibleCommands returns a slice of the Commands with Hidden=false
|
// VisibleCommands returns a slice of the Commands with Hidden=false
|
||||||
func (a *App) VisibleCommands() []Command {
|
func (a *App) VisibleCommands() []Command {
|
||||||
ret := []Command{}
|
var ret []Command
|
||||||
for _, command := range a.Commands {
|
for _, command := range a.Commands {
|
||||||
if !command.Hidden {
|
if !command.Hidden {
|
||||||
ret = append(ret, command)
|
ret = append(ret, command)
|
||||||
|
90
app_test.go
90
app_test.go
@ -47,7 +47,7 @@ func ExampleApp_Run() {
|
|||||||
app.Author = "Harrison"
|
app.Author = "Harrison"
|
||||||
app.Email = "harrison@lolwut.com"
|
app.Email = "harrison@lolwut.com"
|
||||||
app.Authors = []Author{{Name: "Oliver Allen", Email: "oliver@toyshop.com"}}
|
app.Authors = []Author{{Name: "Oliver Allen", Email: "oliver@toyshop.com"}}
|
||||||
app.Run(os.Args)
|
_ = app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// Hello Jeremy
|
// Hello Jeremy
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ func ExampleApp_Run_subcommand() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
_ = app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// Hello, Jeremy
|
// Hello, Jeremy
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ func ExampleApp_Run_appHelp() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
app.Run(os.Args)
|
_ = app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// NAME:
|
// NAME:
|
||||||
// greet - A new cli application
|
// greet - A new cli application
|
||||||
@ -166,7 +166,7 @@ func ExampleApp_Run_commandHelp() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
app.Run(os.Args)
|
_ = app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// NAME:
|
// NAME:
|
||||||
// greet describeit - use it to see a description
|
// greet describeit - use it to see a description
|
||||||
@ -181,7 +181,7 @@ func ExampleApp_Run_commandHelp() {
|
|||||||
func ExampleApp_Run_noAction() {
|
func ExampleApp_Run_noAction() {
|
||||||
app := App{}
|
app := App{}
|
||||||
app.Name = "greet"
|
app.Name = "greet"
|
||||||
app.Run([]string{"greet"})
|
_ = app.Run([]string{"greet"})
|
||||||
// Output:
|
// Output:
|
||||||
// NAME:
|
// NAME:
|
||||||
// greet
|
// greet
|
||||||
@ -208,7 +208,7 @@ func ExampleApp_Run_subcommandNoAction() {
|
|||||||
Description: "This is how we describe describeit the function",
|
Description: "This is how we describe describeit the function",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
app.Run([]string{"greet", "describeit"})
|
_ = app.Run([]string{"greet", "describeit"})
|
||||||
// Output:
|
// Output:
|
||||||
// NAME:
|
// NAME:
|
||||||
// describeit - use it to see a description
|
// describeit - use it to see a description
|
||||||
@ -236,7 +236,7 @@ func ExampleApp_Run_bashComplete_withShortFlag() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
_ = app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// --other
|
// --other
|
||||||
// -o
|
// -o
|
||||||
@ -269,7 +269,7 @@ func ExampleApp_Run_bashComplete_withLongFlag() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
_ = app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// --some-flag
|
// --some-flag
|
||||||
// --similar-flag
|
// --similar-flag
|
||||||
@ -298,7 +298,7 @@ func ExampleApp_Run_bashComplete_withMultipleLongFlag() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
_ = app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// --string
|
// --string
|
||||||
// --string-flag-2
|
// --string-flag-2
|
||||||
@ -332,7 +332,7 @@ func ExampleApp_Run_bashComplete() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
_ = app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// describeit
|
// describeit
|
||||||
// d
|
// d
|
||||||
@ -344,7 +344,7 @@ func ExampleApp_Run_bashComplete() {
|
|||||||
func ExampleApp_Run_zshComplete() {
|
func ExampleApp_Run_zshComplete() {
|
||||||
// set args for examples sake
|
// set args for examples sake
|
||||||
os.Args = []string{"greet", "--generate-bash-completion"}
|
os.Args = []string{"greet", "--generate-bash-completion"}
|
||||||
os.Setenv("_CLI_ZSH_AUTOCOMPLETE_HACK", "1")
|
_ = os.Setenv("_CLI_ZSH_AUTOCOMPLETE_HACK", "1")
|
||||||
|
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
app.Name = "greet"
|
app.Name = "greet"
|
||||||
@ -370,7 +370,7 @@ func ExampleApp_Run_zshComplete() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
_ = app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// describeit:use it to see a description
|
// describeit:use it to see a description
|
||||||
// d:use it to see a description
|
// d:use it to see a description
|
||||||
@ -444,7 +444,7 @@ func TestApp_CommandWithArgBeforeFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
app.Commands = []Command{command}
|
app.Commands = []Command{command}
|
||||||
|
|
||||||
app.Run([]string{"", "cmd", "my-arg", "--option", "my-option"})
|
_ = app.Run([]string{"", "cmd", "my-arg", "--option", "my-option"})
|
||||||
|
|
||||||
expect(t, parsedOption, "my-option")
|
expect(t, parsedOption, "my-option")
|
||||||
expect(t, firstArg, "my-arg")
|
expect(t, firstArg, "my-arg")
|
||||||
@ -474,7 +474,7 @@ func TestApp_CommandWithArgBeforeBoolFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
app.Commands = []Command{command}
|
app.Commands = []Command{command}
|
||||||
|
|
||||||
app.Run([]string{"", "cmd", "my-arg", "--boolflag", "--option", "my-option", "-b", "--secondOption", "fancy-option"})
|
_ = app.Run([]string{"", "cmd", "my-arg", "--boolflag", "--option", "my-option", "-b", "--secondOption", "fancy-option"})
|
||||||
|
|
||||||
expect(t, parsedOption, "my-option")
|
expect(t, parsedOption, "my-option")
|
||||||
expect(t, parsedSecondOption, "fancy-option")
|
expect(t, parsedSecondOption, "fancy-option")
|
||||||
@ -504,7 +504,7 @@ func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
|
|||||||
Before: func(_ *Context) error { return nil },
|
Before: func(_ *Context) error { return nil },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})
|
_ = a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})
|
||||||
|
|
||||||
expect(t, context.Args().Get(0), "abcd")
|
expect(t, context.Args().Get(0), "abcd")
|
||||||
expect(t, context.String("lang"), "spanish")
|
expect(t, context.String("lang"), "spanish")
|
||||||
@ -519,7 +519,7 @@ func TestApp_RunAsSubCommandIncorrectUsage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set := flag.NewFlagSet("", flag.ContinueOnError)
|
set := flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
set.Parse([]string{"", "---foo"})
|
_ = set.Parse([]string{"", "---foo"})
|
||||||
c := &Context{flagSet: set}
|
c := &Context{flagSet: set}
|
||||||
|
|
||||||
err := a.RunAsSubcommand(c)
|
err := a.RunAsSubcommand(c)
|
||||||
@ -545,7 +545,7 @@ func TestApp_CommandWithFlagBeforeTerminator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
app.Commands = []Command{command}
|
app.Commands = []Command{command}
|
||||||
|
|
||||||
app.Run([]string{"", "cmd", "my-arg", "--option", "my-option", "--", "--notARealFlag"})
|
_ = app.Run([]string{"", "cmd", "my-arg", "--option", "my-option", "--", "--notARealFlag"})
|
||||||
|
|
||||||
expect(t, parsedOption, "my-option")
|
expect(t, parsedOption, "my-option")
|
||||||
expect(t, args[0], "my-arg")
|
expect(t, args[0], "my-arg")
|
||||||
@ -566,7 +566,7 @@ func TestApp_CommandWithDash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
app.Commands = []Command{command}
|
app.Commands = []Command{command}
|
||||||
|
|
||||||
app.Run([]string{"", "cmd", "my-arg", "-"})
|
_ = app.Run([]string{"", "cmd", "my-arg", "-"})
|
||||||
|
|
||||||
expect(t, args[0], "my-arg")
|
expect(t, args[0], "my-arg")
|
||||||
expect(t, args[1], "-")
|
expect(t, args[1], "-")
|
||||||
@ -585,7 +585,7 @@ func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
app.Commands = []Command{command}
|
app.Commands = []Command{command}
|
||||||
|
|
||||||
app.Run([]string{"", "cmd", "my-arg", "--", "notAFlagAtAll"})
|
_ = app.Run([]string{"", "cmd", "my-arg", "--", "notAFlagAtAll"})
|
||||||
|
|
||||||
expect(t, args[0], "my-arg")
|
expect(t, args[0], "my-arg")
|
||||||
expect(t, args[1], "--")
|
expect(t, args[1], "--")
|
||||||
@ -646,7 +646,7 @@ func TestApp_Float64Flag(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run([]string{"", "--height", "1.93"})
|
_ = app.Run([]string{"", "--height", "1.93"})
|
||||||
expect(t, meters, 1.93)
|
expect(t, meters, 1.93)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,7 +669,7 @@ func TestApp_ParseSliceFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
app.Commands = []Command{command}
|
app.Commands = []Command{command}
|
||||||
|
|
||||||
app.Run([]string{"", "cmd", "my-arg", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"})
|
_ = app.Run([]string{"", "cmd", "my-arg", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"})
|
||||||
|
|
||||||
IntsEquals := func(a, b []int) bool {
|
IntsEquals := func(a, b []int) bool {
|
||||||
if len(a) != len(b) {
|
if len(a) != len(b) {
|
||||||
@ -725,7 +725,7 @@ func TestApp_ParseSliceFlagsWithMissingValue(t *testing.T) {
|
|||||||
}
|
}
|
||||||
app.Commands = []Command{command}
|
app.Commands = []Command{command}
|
||||||
|
|
||||||
app.Run([]string{"", "cmd", "my-arg", "-a", "2", "-str", "A"})
|
_ = app.Run([]string{"", "cmd", "my-arg", "-a", "2", "-str", "A"})
|
||||||
|
|
||||||
var expectedIntSlice = []int{2}
|
var expectedIntSlice = []int{2}
|
||||||
var expectedStringSlice = []string{"A"}
|
var expectedStringSlice = []string{"A"}
|
||||||
@ -978,7 +978,7 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "error_case_empty_input_with_required_flag_on_command",
|
testCase: "error_case_empty_input_with_required_flag_on_command",
|
||||||
appRunInput: []string{"myCLI", "myCommand"},
|
appRunInput: []string{"myCLI", "myCommand"},
|
||||||
appCommands: []Command{Command{
|
appCommands: []Command{{
|
||||||
Name: "myCommand",
|
Name: "myCommand",
|
||||||
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
}},
|
}},
|
||||||
@ -987,9 +987,9 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "error_case_empty_input_with_required_flag_on_subcommand",
|
testCase: "error_case_empty_input_with_required_flag_on_subcommand",
|
||||||
appRunInput: []string{"myCLI", "myCommand", "mySubCommand"},
|
appRunInput: []string{"myCLI", "myCommand", "mySubCommand"},
|
||||||
appCommands: []Command{Command{
|
appCommands: []Command{{
|
||||||
Name: "myCommand",
|
Name: "myCommand",
|
||||||
Subcommands: []Command{Command{
|
Subcommands: []Command{{
|
||||||
Name: "mySubCommand",
|
Name: "mySubCommand",
|
||||||
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
}},
|
}},
|
||||||
@ -1005,7 +1005,7 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "valid_case_help_input_with_required_flag_on_command",
|
testCase: "valid_case_help_input_with_required_flag_on_command",
|
||||||
appRunInput: []string{"myCLI", "myCommand", "--help"},
|
appRunInput: []string{"myCLI", "myCommand", "--help"},
|
||||||
appCommands: []Command{Command{
|
appCommands: []Command{{
|
||||||
Name: "myCommand",
|
Name: "myCommand",
|
||||||
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
}},
|
}},
|
||||||
@ -1013,9 +1013,9 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "valid_case_help_input_with_required_flag_on_subcommand",
|
testCase: "valid_case_help_input_with_required_flag_on_subcommand",
|
||||||
appRunInput: []string{"myCLI", "myCommand", "mySubCommand", "--help"},
|
appRunInput: []string{"myCLI", "myCommand", "mySubCommand", "--help"},
|
||||||
appCommands: []Command{Command{
|
appCommands: []Command{{
|
||||||
Name: "myCommand",
|
Name: "myCommand",
|
||||||
Subcommands: []Command{Command{
|
Subcommands: []Command{{
|
||||||
Name: "mySubCommand",
|
Name: "mySubCommand",
|
||||||
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
}},
|
}},
|
||||||
@ -1031,7 +1031,7 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "error_case_optional_input_with_required_flag_on_command",
|
testCase: "error_case_optional_input_with_required_flag_on_command",
|
||||||
appRunInput: []string{"myCLI", "myCommand", "--optional", "cats"},
|
appRunInput: []string{"myCLI", "myCommand", "--optional", "cats"},
|
||||||
appCommands: []Command{Command{
|
appCommands: []Command{{
|
||||||
Name: "myCommand",
|
Name: "myCommand",
|
||||||
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}, StringFlag{Name: "optional"}},
|
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}, StringFlag{Name: "optional"}},
|
||||||
}},
|
}},
|
||||||
@ -1040,9 +1040,9 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "error_case_optional_input_with_required_flag_on_subcommand",
|
testCase: "error_case_optional_input_with_required_flag_on_subcommand",
|
||||||
appRunInput: []string{"myCLI", "myCommand", "mySubCommand", "--optional", "cats"},
|
appRunInput: []string{"myCLI", "myCommand", "mySubCommand", "--optional", "cats"},
|
||||||
appCommands: []Command{Command{
|
appCommands: []Command{{
|
||||||
Name: "myCommand",
|
Name: "myCommand",
|
||||||
Subcommands: []Command{Command{
|
Subcommands: []Command{{
|
||||||
Name: "mySubCommand",
|
Name: "mySubCommand",
|
||||||
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}, StringFlag{Name: "optional"}},
|
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}, StringFlag{Name: "optional"}},
|
||||||
}},
|
}},
|
||||||
@ -1058,7 +1058,7 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "valid_case_required_flag_input_on_command",
|
testCase: "valid_case_required_flag_input_on_command",
|
||||||
appRunInput: []string{"myCLI", "myCommand", "--requiredFlag", "cats"},
|
appRunInput: []string{"myCLI", "myCommand", "--requiredFlag", "cats"},
|
||||||
appCommands: []Command{Command{
|
appCommands: []Command{{
|
||||||
Name: "myCommand",
|
Name: "myCommand",
|
||||||
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
}},
|
}},
|
||||||
@ -1066,9 +1066,9 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testCase: "valid_case_required_flag_input_on_subcommand",
|
testCase: "valid_case_required_flag_input_on_subcommand",
|
||||||
appRunInput: []string{"myCLI", "myCommand", "mySubCommand", "--requiredFlag", "cats"},
|
appRunInput: []string{"myCLI", "myCommand", "mySubCommand", "--requiredFlag", "cats"},
|
||||||
appCommands: []Command{Command{
|
appCommands: []Command{{
|
||||||
Name: "myCommand",
|
Name: "myCommand",
|
||||||
Subcommands: []Command{Command{
|
Subcommands: []Command{{
|
||||||
Name: "mySubCommand",
|
Name: "mySubCommand",
|
||||||
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
Flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}},
|
||||||
}},
|
}},
|
||||||
@ -1111,7 +1111,7 @@ func TestAppHelpPrinter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
app.Run([]string{"-h"})
|
_ = app.Run([]string{"-h"})
|
||||||
|
|
||||||
if wasCalled == false {
|
if wasCalled == false {
|
||||||
t.Errorf("Help printer expected to be called, but was not")
|
t.Errorf("Help printer expected to be called, but was not")
|
||||||
@ -1158,7 +1158,7 @@ func TestApp_CommandNotFound(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run([]string{"command", "foo"})
|
_ = app.Run([]string{"command", "foo"})
|
||||||
|
|
||||||
expect(t, counts.CommandNotFound, 1)
|
expect(t, counts.CommandNotFound, 1)
|
||||||
expect(t, counts.SubCommand, 0)
|
expect(t, counts.SubCommand, 0)
|
||||||
@ -1568,7 +1568,7 @@ func TestApp_Run_Categories(t *testing.T) {
|
|||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
app.Writer = buf
|
app.Writer = buf
|
||||||
|
|
||||||
app.Run([]string{"categories"})
|
_ = app.Run([]string{"categories"})
|
||||||
|
|
||||||
expect := CommandCategories{
|
expect := CommandCategories{
|
||||||
&CommandCategory{
|
&CommandCategory{
|
||||||
@ -1975,7 +1975,7 @@ func TestHandleExitCoder_Custom(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.ExitErrHandler = func(_ *Context, _ error) {
|
app.ExitErrHandler = func(_ *Context, _ error) {
|
||||||
fmt.Fprintln(ErrWriter, "I'm a Custom error handler, I print what I want!")
|
_, _ = fmt.Fprintln(ErrWriter, "I'm a Custom error handler, I print what I want!")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := NewContext(app, fs, nil)
|
ctx := NewContext(app, fs, nil)
|
||||||
@ -1994,14 +1994,14 @@ func TestHandleAction_WithUnknownPanic(t *testing.T) {
|
|||||||
|
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
app.Action = func(ctx *Context) error {
|
app.Action = func(ctx *Context) error {
|
||||||
fn(ctx)
|
_ = fn(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
fs, err := flagSet(app.Name, app.Flags)
|
fs, err := flagSet(app.Name, app.Flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error creating FlagSet: %s", err)
|
t.Errorf("error creating FlagSet: %s", err)
|
||||||
}
|
}
|
||||||
HandleAction(app.Action, NewContext(app, fs, nil))
|
_ = HandleAction(app.Action, NewContext(app, fs, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShellCompletionForIncompleteFlags(t *testing.T) {
|
func TestShellCompletionForIncompleteFlags(t *testing.T) {
|
||||||
@ -2019,12 +2019,12 @@ func TestShellCompletionForIncompleteFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range command.Names() {
|
for _, name := range command.Names() {
|
||||||
fmt.Fprintln(ctx.App.Writer, name)
|
_, _ = fmt.Fprintln(ctx.App.Writer, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, flag := range ctx.App.Flags {
|
for _, f := range ctx.App.Flags {
|
||||||
for _, name := range strings.Split(flag.GetName(), ",") {
|
for _, name := range strings.Split(f.GetName(), ",") {
|
||||||
if name == BashCompletionFlag.GetName() {
|
if name == BashCompletionFlag.GetName() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -2032,9 +2032,9 @@ func TestShellCompletionForIncompleteFlags(t *testing.T) {
|
|||||||
switch name = strings.TrimSpace(name); len(name) {
|
switch name = strings.TrimSpace(name); len(name) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
fmt.Fprintln(ctx.App.Writer, "-"+name)
|
_, _ = fmt.Fprintln(ctx.App.Writer, "-"+name)
|
||||||
default:
|
default:
|
||||||
fmt.Fprintln(ctx.App.Writer, "--"+name)
|
_, _ = fmt.Fprintln(ctx.App.Writer, "--"+name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
command.go
14
command.go
@ -125,9 +125,9 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
context.App.handleExitCoder(context, err)
|
context.App.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error())
|
_, _ = fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error())
|
||||||
fmt.Fprintln(context.App.Writer)
|
_, _ = fmt.Fprintln(context.App.Writer)
|
||||||
ShowCommandHelp(context, c.Name)
|
_ = ShowCommandHelp(context, c.Name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
|
|
||||||
cerr := checkRequiredFlags(c.Flags, context)
|
cerr := checkRequiredFlags(c.Flags, context)
|
||||||
if cerr != nil {
|
if cerr != nil {
|
||||||
ShowCommandHelp(context, c.Name)
|
_ = ShowCommandHelp(context, c.Name)
|
||||||
return cerr
|
return cerr
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
if c.Before != nil {
|
if c.Before != nil {
|
||||||
err = c.Before(context)
|
err = c.Before(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ShowCommandHelp(context, c.Name)
|
_ = ShowCommandHelp(context, c.Name)
|
||||||
context.App.handleExitCoder(context, err)
|
context.App.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -272,7 +272,7 @@ func reorderArgs(args []string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func translateShortOptions(set *flag.FlagSet, flagArgs Args) []string {
|
func translateShortOptions(set *flag.FlagSet, flagArgs Args) []string {
|
||||||
allCharsFlags := func (s string) bool {
|
allCharsFlags := func(s string) bool {
|
||||||
for i := range s {
|
for i := range s {
|
||||||
f := set.Lookup(string(s[i]))
|
f := set.Lookup(string(s[i]))
|
||||||
if f == nil {
|
if f == nil {
|
||||||
@ -285,7 +285,7 @@ func translateShortOptions(set *flag.FlagSet, flagArgs Args) []string {
|
|||||||
// separate combined flags
|
// separate combined flags
|
||||||
var flagArgsSeparated []string
|
var flagArgsSeparated []string
|
||||||
for _, flagArg := range flagArgs {
|
for _, flagArg := range flagArgs {
|
||||||
if strings.HasPrefix(flagArg, "-") && strings.HasPrefix(flagArg, "--") == false && len(flagArg) > 2 {
|
if strings.HasPrefix(flagArg, "-") && !strings.HasPrefix(flagArg, "--") && len(flagArg) > 2 {
|
||||||
if !allCharsFlags(flagArg[1:]) {
|
if !allCharsFlags(flagArg[1:]) {
|
||||||
flagArgsSeparated = append(flagArgsSeparated, flagArg)
|
flagArgsSeparated = append(flagArgsSeparated, flagArg)
|
||||||
continue
|
continue
|
||||||
|
@ -35,7 +35,7 @@ func TestCommandFlagParsing(t *testing.T) {
|
|||||||
app := NewApp()
|
app := NewApp()
|
||||||
app.Writer = ioutil.Discard
|
app.Writer = ioutil.Discard
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
set.Parse(c.testArgs)
|
_ = set.Parse(c.testArgs)
|
||||||
|
|
||||||
context := NewContext(app, set, nil)
|
context := NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -59,9 +59,9 @@ func TestCommandFlagParsing(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseAndRunShortOpts(t *testing.T) {
|
func TestParseAndRunShortOpts(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
testArgs []string
|
testArgs []string
|
||||||
expectedErr error
|
expectedErr error
|
||||||
expectedArgs []string
|
expectedArgs []string
|
||||||
}{
|
}{
|
||||||
{[]string{"foo", "test", "-a"}, nil, []string{}},
|
{[]string{"foo", "test", "-a"}, nil, []string{}},
|
||||||
{[]string{"foo", "test", "-c", "arg1", "arg2"}, nil, []string{"arg1", "arg2"}},
|
{[]string{"foo", "test", "-c", "arg1", "arg2"}, nil, []string{"arg1", "arg2"}},
|
||||||
@ -71,18 +71,18 @@ func TestParseAndRunShortOpts(t *testing.T) {
|
|||||||
{[]string{"foo", "test", "-cf"}, nil, []string{}},
|
{[]string{"foo", "test", "-cf"}, nil, []string{}},
|
||||||
{[]string{"foo", "test", "-acf"}, nil, []string{}},
|
{[]string{"foo", "test", "-acf"}, nil, []string{}},
|
||||||
{[]string{"foo", "test", "-invalid"}, errors.New("flag provided but not defined: -invalid"), []string{}},
|
{[]string{"foo", "test", "-invalid"}, errors.New("flag provided but not defined: -invalid"), []string{}},
|
||||||
{[]string{"foo", "test", "-acf", "arg1", "-invalid"}, nil, []string{"arg1" ,"-invalid"}},
|
{[]string{"foo", "test", "-acf", "arg1", "-invalid"}, nil, []string{"arg1", "-invalid"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
var args []string
|
var args []string
|
||||||
cmd := Command{
|
cmd := Command{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Usage: "this is for testing",
|
Usage: "this is for testing",
|
||||||
Description: "testing",
|
Description: "testing",
|
||||||
Action: func(c *Context) error {
|
Action: func(c *Context) error {
|
||||||
args = c.Args()
|
args = c.Args()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
SkipArgReorder: true,
|
SkipArgReorder: true,
|
||||||
UseShortOptionHandling: true,
|
UseShortOptionHandling: true,
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
@ -304,7 +304,7 @@ func TestCommandFlagReordering(t *testing.T) {
|
|||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
value := ""
|
value := ""
|
||||||
args := []string{}
|
var args []string
|
||||||
app := &App{
|
app := &App{
|
||||||
Commands: []Command{
|
Commands: []Command{
|
||||||
{
|
{
|
||||||
@ -339,7 +339,7 @@ func TestCommandSkipFlagParsing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
args := []string{}
|
var args []string
|
||||||
app := &App{
|
app := &App{
|
||||||
Commands: []Command{
|
Commands: []Command{
|
||||||
{
|
{
|
||||||
|
10
context.go
10
context.go
@ -139,8 +139,8 @@ func (c *Context) GlobalIsSet(name string) bool {
|
|||||||
|
|
||||||
// FlagNames returns a slice of flag names used in this context.
|
// FlagNames returns a slice of flag names used in this context.
|
||||||
func (c *Context) FlagNames() (names []string) {
|
func (c *Context) FlagNames() (names []string) {
|
||||||
for _, flag := range c.Command.Flags {
|
for _, f := range c.Command.Flags {
|
||||||
name := strings.Split(flag.GetName(), ",")[0]
|
name := strings.Split(f.GetName(), ",")[0]
|
||||||
if name == "help" {
|
if name == "help" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -151,8 +151,8 @@ func (c *Context) FlagNames() (names []string) {
|
|||||||
|
|
||||||
// GlobalFlagNames returns a slice of global flag names used by the app.
|
// GlobalFlagNames returns a slice of global flag names used by the app.
|
||||||
func (c *Context) GlobalFlagNames() (names []string) {
|
func (c *Context) GlobalFlagNames() (names []string) {
|
||||||
for _, flag := range c.App.Flags {
|
for _, f := range c.App.Flags {
|
||||||
name := strings.Split(flag.GetName(), ",")[0]
|
name := strings.Split(f.GetName(), ",")[0]
|
||||||
if name == "help" || name == "version" {
|
if name == "help" || name == "version" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) {
|
|||||||
switch ff.Value.(type) {
|
switch ff.Value.(type) {
|
||||||
case *StringSlice:
|
case *StringSlice:
|
||||||
default:
|
default:
|
||||||
set.Set(name, ff.Value.String())
|
_ = set.Set(name, ff.Value.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,9 +99,9 @@ func TestContext_GlobalFloat64(t *testing.T) {
|
|||||||
|
|
||||||
func TestContext_Duration(t *testing.T) {
|
func TestContext_Duration(t *testing.T) {
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
set.Duration("myflag", time.Duration(12*time.Second), "doc")
|
set.Duration("myflag", 12*time.Second, "doc")
|
||||||
c := NewContext(nil, set, nil)
|
c := NewContext(nil, set, nil)
|
||||||
expect(t, c.Duration("myflag"), time.Duration(12*time.Second))
|
expect(t, c.Duration("myflag"), 12*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContext_String(t *testing.T) {
|
func TestContext_String(t *testing.T) {
|
||||||
@ -153,7 +153,7 @@ func TestContext_Args(t *testing.T) {
|
|||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
set.Bool("myflag", false, "doc")
|
set.Bool("myflag", false, "doc")
|
||||||
c := NewContext(nil, set, nil)
|
c := NewContext(nil, set, nil)
|
||||||
set.Parse([]string{"--myflag", "bat", "baz"})
|
_ = set.Parse([]string{"--myflag", "bat", "baz"})
|
||||||
expect(t, len(c.Args()), 2)
|
expect(t, len(c.Args()), 2)
|
||||||
expect(t, c.Bool("myflag"), true)
|
expect(t, c.Bool("myflag"), true)
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ func TestContext_NArg(t *testing.T) {
|
|||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
set.Bool("myflag", false, "doc")
|
set.Bool("myflag", false, "doc")
|
||||||
c := NewContext(nil, set, nil)
|
c := NewContext(nil, set, nil)
|
||||||
set.Parse([]string{"--myflag", "bat", "baz"})
|
_ = set.Parse([]string{"--myflag", "bat", "baz"})
|
||||||
expect(t, c.NArg(), 2)
|
expect(t, c.NArg(), 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,8 +174,8 @@ func TestContext_IsSet(t *testing.T) {
|
|||||||
globalSet.Bool("myflagGlobal", true, "doc")
|
globalSet.Bool("myflagGlobal", true, "doc")
|
||||||
globalCtx := NewContext(nil, globalSet, nil)
|
globalCtx := NewContext(nil, globalSet, nil)
|
||||||
c := NewContext(nil, set, globalCtx)
|
c := NewContext(nil, set, globalCtx)
|
||||||
set.Parse([]string{"--myflag", "bat", "baz"})
|
_ = set.Parse([]string{"--myflag", "bat", "baz"})
|
||||||
globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
_ = globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
||||||
expect(t, c.IsSet("myflag"), true)
|
expect(t, c.IsSet("myflag"), true)
|
||||||
expect(t, c.IsSet("otherflag"), false)
|
expect(t, c.IsSet("otherflag"), false)
|
||||||
expect(t, c.IsSet("bogusflag"), false)
|
expect(t, c.IsSet("bogusflag"), false)
|
||||||
@ -193,8 +193,8 @@ func TestContext_IsSet_fromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
clearenv()
|
clearenv()
|
||||||
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
_ = os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
||||||
os.Setenv("APP_PASSWORD", "")
|
_ = os.Setenv("APP_PASSWORD", "")
|
||||||
a := App{
|
a := App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
||||||
@ -214,7 +214,7 @@ func TestContext_IsSet_fromEnv(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
a.Run([]string{"run"})
|
_ = a.Run([]string{"run"})
|
||||||
expect(t, timeoutIsSet, true)
|
expect(t, timeoutIsSet, true)
|
||||||
expect(t, tIsSet, true)
|
expect(t, tIsSet, true)
|
||||||
expect(t, passwordIsSet, true)
|
expect(t, passwordIsSet, true)
|
||||||
@ -222,8 +222,8 @@ func TestContext_IsSet_fromEnv(t *testing.T) {
|
|||||||
expect(t, noEnvVarIsSet, false)
|
expect(t, noEnvVarIsSet, false)
|
||||||
expect(t, nIsSet, false)
|
expect(t, nIsSet, false)
|
||||||
|
|
||||||
os.Setenv("APP_UNPARSABLE", "foobar")
|
_ = os.Setenv("APP_UNPARSABLE", "foobar")
|
||||||
a.Run([]string{"run"})
|
_ = a.Run([]string{"run"})
|
||||||
expect(t, unparsableIsSet, false)
|
expect(t, unparsableIsSet, false)
|
||||||
expect(t, uIsSet, false)
|
expect(t, uIsSet, false)
|
||||||
}
|
}
|
||||||
@ -237,8 +237,8 @@ func TestContext_GlobalIsSet(t *testing.T) {
|
|||||||
globalSet.Bool("myflagGlobalUnset", true, "doc")
|
globalSet.Bool("myflagGlobalUnset", true, "doc")
|
||||||
globalCtx := NewContext(nil, globalSet, nil)
|
globalCtx := NewContext(nil, globalSet, nil)
|
||||||
c := NewContext(nil, set, globalCtx)
|
c := NewContext(nil, set, globalCtx)
|
||||||
set.Parse([]string{"--myflag", "bat", "baz"})
|
_ = set.Parse([]string{"--myflag", "bat", "baz"})
|
||||||
globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
_ = globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
||||||
expect(t, c.GlobalIsSet("myflag"), false)
|
expect(t, c.GlobalIsSet("myflag"), false)
|
||||||
expect(t, c.GlobalIsSet("otherflag"), false)
|
expect(t, c.GlobalIsSet("otherflag"), false)
|
||||||
expect(t, c.GlobalIsSet("bogusflag"), false)
|
expect(t, c.GlobalIsSet("bogusflag"), false)
|
||||||
@ -261,9 +261,9 @@ func TestContext_GlobalIsSet_fromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
clearenv()
|
clearenv()
|
||||||
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
_ = os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
||||||
os.Setenv("APP_PASSWORD", "badpass")
|
_ = os.Setenv("APP_PASSWORD", "badpass")
|
||||||
os.Setenv("APP_OVERRIDE", "overridden")
|
_ = os.Setenv("APP_OVERRIDE", "overridden")
|
||||||
a := App{
|
a := App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
||||||
@ -308,7 +308,7 @@ func TestContext_GlobalIsSet_fromEnv(t *testing.T) {
|
|||||||
expect(t, oIsSet, true)
|
expect(t, oIsSet, true)
|
||||||
expect(t, overrideValue, "overridden")
|
expect(t, overrideValue, "overridden")
|
||||||
|
|
||||||
os.Setenv("APP_UNPARSABLE", "foobar")
|
_ = os.Setenv("APP_UNPARSABLE", "foobar")
|
||||||
if err := a.Run([]string{"run"}); err != nil {
|
if err := a.Run([]string{"run"}); err != nil {
|
||||||
t.Logf("error running Run(): %+v", err)
|
t.Logf("error running Run(): %+v", err)
|
||||||
}
|
}
|
||||||
@ -324,8 +324,8 @@ func TestContext_NumFlags(t *testing.T) {
|
|||||||
globalSet.Bool("myflagGlobal", true, "doc")
|
globalSet.Bool("myflagGlobal", true, "doc")
|
||||||
globalCtx := NewContext(nil, globalSet, nil)
|
globalCtx := NewContext(nil, globalSet, nil)
|
||||||
c := NewContext(nil, set, globalCtx)
|
c := NewContext(nil, set, globalCtx)
|
||||||
set.Parse([]string{"--myflag", "--otherflag=foo"})
|
_ = set.Parse([]string{"--myflag", "--otherflag=foo"})
|
||||||
globalSet.Parse([]string{"--myflagGlobal"})
|
_ = globalSet.Parse([]string{"--myflagGlobal"})
|
||||||
expect(t, c.NumFlags(), 2)
|
expect(t, c.NumFlags(), 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ func TestContext_GlobalFlag(t *testing.T) {
|
|||||||
globalFlagSet = c.GlobalIsSet("global")
|
globalFlagSet = c.GlobalIsSet("global")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
app.Run([]string{"command", "-g", "foo"})
|
_ = app.Run([]string{"command", "-g", "foo"})
|
||||||
expect(t, globalFlag, "foo")
|
expect(t, globalFlag, "foo")
|
||||||
expect(t, globalFlagSet, true)
|
expect(t, globalFlagSet, true)
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ func TestContext_GlobalFlagsInSubcommands(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run([]string{"command", "-d", "foo", "-p", "bar"})
|
_ = app.Run([]string{"command", "-d", "foo", "-p", "bar"})
|
||||||
|
|
||||||
expect(t, subcommandRun, true)
|
expect(t, subcommandRun, true)
|
||||||
expect(t, parentFlag, true)
|
expect(t, parentFlag, true)
|
||||||
@ -391,7 +391,7 @@ func TestContext_Set(t *testing.T) {
|
|||||||
c := NewContext(nil, set, nil)
|
c := NewContext(nil, set, nil)
|
||||||
|
|
||||||
expect(t, c.IsSet("int"), false)
|
expect(t, c.IsSet("int"), false)
|
||||||
c.Set("int", "1")
|
_ = c.Set("int", "1")
|
||||||
expect(t, c.Int("int"), 1)
|
expect(t, c.Int("int"), 1)
|
||||||
expect(t, c.IsSet("int"), true)
|
expect(t, c.IsSet("int"), true)
|
||||||
}
|
}
|
||||||
@ -406,12 +406,12 @@ func TestContext_GlobalSet(t *testing.T) {
|
|||||||
pc := NewContext(nil, gSet, nil)
|
pc := NewContext(nil, gSet, nil)
|
||||||
c := NewContext(nil, set, pc)
|
c := NewContext(nil, set, pc)
|
||||||
|
|
||||||
c.Set("int", "1")
|
_ = c.Set("int", "1")
|
||||||
expect(t, c.Int("int"), 1)
|
expect(t, c.Int("int"), 1)
|
||||||
expect(t, c.GlobalInt("int"), 5)
|
expect(t, c.GlobalInt("int"), 5)
|
||||||
|
|
||||||
expect(t, c.GlobalIsSet("int"), false)
|
expect(t, c.GlobalIsSet("int"), false)
|
||||||
c.GlobalSet("int", "1")
|
_ = c.GlobalSet("int", "1")
|
||||||
expect(t, c.Int("int"), 1)
|
expect(t, c.Int("int"), 1)
|
||||||
expect(t, c.GlobalInt("int"), 1)
|
expect(t, c.GlobalInt("int"), 1)
|
||||||
expect(t, c.GlobalIsSet("int"), true)
|
expect(t, c.GlobalIsSet("int"), true)
|
||||||
@ -525,10 +525,10 @@ func TestCheckRequiredFlags(t *testing.T) {
|
|||||||
for _, flags := range test.flags {
|
for _, flags := range test.flags {
|
||||||
flags.Apply(set)
|
flags.Apply(set)
|
||||||
}
|
}
|
||||||
set.Parse(test.parseInput)
|
_ = set.Parse(test.parseInput)
|
||||||
if test.envVarInput[0] != "" {
|
if test.envVarInput[0] != "" {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv(test.envVarInput[0], test.envVarInput[1])
|
_ = os.Setenv(test.envVarInput[0], test.envVarInput[1])
|
||||||
}
|
}
|
||||||
ctx := &Context{}
|
ctx := &Context{}
|
||||||
context := NewContext(ctx.App, set, ctx)
|
context := NewContext(ctx.App, set, ctx)
|
||||||
|
44
flag.go
44
flag.go
@ -126,7 +126,7 @@ type Generic interface {
|
|||||||
// provided by the user for parsing by the flag
|
// provided by the user for parsing by the flag
|
||||||
// Ignores parsing errors
|
// Ignores parsing errors
|
||||||
func (f GenericFlag) Apply(set *flag.FlagSet) {
|
func (f GenericFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError takes the flagset and calls Set on the generic flag with the value
|
// ApplyWithError takes the flagset and calls Set on the generic flag with the value
|
||||||
@ -173,7 +173,7 @@ func (f *StringSlice) Get() interface{} {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
|
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -234,7 +234,7 @@ func (f *IntSlice) Get() interface{} {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
|
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -295,7 +295,7 @@ func (f *Int64Slice) Get() interface{} {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f Int64SliceFlag) Apply(set *flag.FlagSet) {
|
func (f Int64SliceFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -327,7 +327,7 @@ func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f BoolFlag) Apply(set *flag.FlagSet) {
|
func (f BoolFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -359,7 +359,7 @@ func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f BoolTFlag) Apply(set *flag.FlagSet) {
|
func (f BoolTFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -392,7 +392,7 @@ func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f StringFlag) Apply(set *flag.FlagSet) {
|
func (f StringFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -415,7 +415,7 @@ func (f StringFlag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f IntFlag) Apply(set *flag.FlagSet) {
|
func (f IntFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -442,7 +442,7 @@ func (f IntFlag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f Int64Flag) Apply(set *flag.FlagSet) {
|
func (f Int64Flag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -470,7 +470,7 @@ func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f UintFlag) Apply(set *flag.FlagSet) {
|
func (f UintFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -498,7 +498,7 @@ func (f UintFlag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f Uint64Flag) Apply(set *flag.FlagSet) {
|
func (f Uint64Flag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -509,7 +509,7 @@ func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
return fmt.Errorf("could not parse %s as uint64 value for flag %s: %s", envVal, f.Name, err)
|
return fmt.Errorf("could not parse %s as uint64 value for flag %s: %s", envVal, f.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Value = uint64(envValInt)
|
f.Value = envValInt
|
||||||
}
|
}
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
@ -526,7 +526,7 @@ func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f DurationFlag) Apply(set *flag.FlagSet) {
|
func (f DurationFlag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -554,7 +554,7 @@ func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
// Apply populates the flag given the flag set and environment
|
// Apply populates the flag given the flag set and environment
|
||||||
// Ignores errors
|
// Ignores errors
|
||||||
func (f Float64Flag) Apply(set *flag.FlagSet) {
|
func (f Float64Flag) Apply(set *flag.FlagSet) {
|
||||||
f.ApplyWithError(set)
|
_ = f.ApplyWithError(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyWithError populates the flag given the flag set and environment
|
// ApplyWithError populates the flag given the flag set and environment
|
||||||
@ -565,7 +565,7 @@ func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
return fmt.Errorf("could not parse %s as float64 value for flag %s: %s", envVal, f.Name, err)
|
return fmt.Errorf("could not parse %s as float64 value for flag %s: %s", envVal, f.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Value = float64(envValFloat)
|
f.Value = envValFloat
|
||||||
}
|
}
|
||||||
|
|
||||||
eachName(f.Name, func(name string) {
|
eachName(f.Name, func(name string) {
|
||||||
@ -580,11 +580,11 @@ func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func visibleFlags(fl []Flag) []Flag {
|
func visibleFlags(fl []Flag) []Flag {
|
||||||
visible := []Flag{}
|
var visible []Flag
|
||||||
for _, flag := range fl {
|
for _, f := range fl {
|
||||||
field := flagValue(flag).FieldByName("Hidden")
|
field := flagValue(f).FieldByName("Hidden")
|
||||||
if !field.IsValid() || !field.Bool() {
|
if !field.IsValid() || !field.Bool() {
|
||||||
visible = append(visible, flag)
|
visible = append(visible, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return visible
|
return visible
|
||||||
@ -729,7 +729,7 @@ func stringifyFlag(f Flag) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stringifyIntSliceFlag(f IntSliceFlag) string {
|
func stringifyIntSliceFlag(f IntSliceFlag) string {
|
||||||
defaultVals := []string{}
|
var defaultVals []string
|
||||||
if f.Value != nil && len(f.Value.Value()) > 0 {
|
if f.Value != nil && len(f.Value.Value()) > 0 {
|
||||||
for _, i := range f.Value.Value() {
|
for _, i := range f.Value.Value() {
|
||||||
defaultVals = append(defaultVals, strconv.Itoa(i))
|
defaultVals = append(defaultVals, strconv.Itoa(i))
|
||||||
@ -740,7 +740,7 @@ func stringifyIntSliceFlag(f IntSliceFlag) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stringifyInt64SliceFlag(f Int64SliceFlag) string {
|
func stringifyInt64SliceFlag(f Int64SliceFlag) string {
|
||||||
defaultVals := []string{}
|
var defaultVals []string
|
||||||
if f.Value != nil && len(f.Value.Value()) > 0 {
|
if f.Value != nil && len(f.Value.Value()) > 0 {
|
||||||
for _, i := range f.Value.Value() {
|
for _, i := range f.Value.Value() {
|
||||||
defaultVals = append(defaultVals, strconv.FormatInt(i, 10))
|
defaultVals = append(defaultVals, strconv.FormatInt(i, 10))
|
||||||
@ -751,7 +751,7 @@ func stringifyInt64SliceFlag(f Int64SliceFlag) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stringifyStringSliceFlag(f StringSliceFlag) string {
|
func stringifyStringSliceFlag(f StringSliceFlag) string {
|
||||||
defaultVals := []string{}
|
var defaultVals []string
|
||||||
if f.Value != nil && len(f.Value.Value()) > 0 {
|
if f.Value != nil && len(f.Value.Value()) > 0 {
|
||||||
for _, s := range f.Value.Value() {
|
for _, s := range f.Value.Value() {
|
||||||
if len(s) > 0 {
|
if len(s) > 0 {
|
||||||
|
220
flag_test.go
220
flag_test.go
@ -89,7 +89,7 @@ func TestFlagsFromEnv(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range flagTests {
|
for _, 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)
|
||||||
a := App{
|
a := App{
|
||||||
Flags: []Flag{test.flag},
|
Flags: []Flag{test.flag},
|
||||||
Action: func(ctx *Context) error {
|
Action: func(ctx *Context) error {
|
||||||
@ -145,7 +145,7 @@ func TestStringFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_FOO", "derp")
|
_ = os.Setenv("APP_FOO", "derp")
|
||||||
for _, test := range stringFlagTests {
|
for _, test := range stringFlagTests {
|
||||||
flag := StringFlag{Name: test.name, Value: test.value, EnvVar: "APP_FOO"}
|
flag := StringFlag{Name: test.name, Value: test.value, EnvVar: "APP_FOO"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -244,22 +244,22 @@ var stringSliceFlagTests = []struct {
|
|||||||
}{
|
}{
|
||||||
{"foo", func() *StringSlice {
|
{"foo", func() *StringSlice {
|
||||||
s := &StringSlice{}
|
s := &StringSlice{}
|
||||||
s.Set("")
|
_ = s.Set("")
|
||||||
return s
|
return s
|
||||||
}(), "--foo value\t"},
|
}(), "--foo value\t"},
|
||||||
{"f", func() *StringSlice {
|
{"f", func() *StringSlice {
|
||||||
s := &StringSlice{}
|
s := &StringSlice{}
|
||||||
s.Set("")
|
_ = s.Set("")
|
||||||
return s
|
return s
|
||||||
}(), "-f value\t"},
|
}(), "-f value\t"},
|
||||||
{"f", func() *StringSlice {
|
{"f", func() *StringSlice {
|
||||||
s := &StringSlice{}
|
s := &StringSlice{}
|
||||||
s.Set("Lipstick")
|
_ = s.Set("Lipstick")
|
||||||
return s
|
return s
|
||||||
}(), "-f value\t(default: \"Lipstick\")"},
|
}(), "-f value\t(default: \"Lipstick\")"},
|
||||||
{"test", func() *StringSlice {
|
{"test", func() *StringSlice {
|
||||||
s := &StringSlice{}
|
s := &StringSlice{}
|
||||||
s.Set("Something")
|
_ = s.Set("Something")
|
||||||
return s
|
return s
|
||||||
}(), "--test value\t(default: \"Something\")"},
|
}(), "--test value\t(default: \"Something\")"},
|
||||||
}
|
}
|
||||||
@ -277,7 +277,7 @@ func TestStringSliceFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
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, Value: test.value, EnvVar: "APP_QWWX"}
|
flag := StringSliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_QWWX"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -313,7 +313,7 @@ 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")
|
||||||
for _, test := range intFlagTests {
|
for _, test := range intFlagTests {
|
||||||
flag := IntFlag{Name: test.name, EnvVar: "APP_BAR"}
|
flag := IntFlag{Name: test.name, EnvVar: "APP_BAR"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -349,7 +349,7 @@ func TestInt64FlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestInt64FlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestInt64FlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_BAR", "2")
|
_ = os.Setenv("APP_BAR", "2")
|
||||||
for _, test := range int64FlagTests {
|
for _, test := range int64FlagTests {
|
||||||
flag := IntFlag{Name: test.name, EnvVar: "APP_BAR"}
|
flag := IntFlag{Name: test.name, EnvVar: "APP_BAR"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -385,7 +385,7 @@ func TestUintFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestUintFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestUintFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_BAR", "2")
|
_ = os.Setenv("APP_BAR", "2")
|
||||||
for _, test := range uintFlagTests {
|
for _, test := range uintFlagTests {
|
||||||
flag := UintFlag{Name: test.name, EnvVar: "APP_BAR"}
|
flag := UintFlag{Name: test.name, EnvVar: "APP_BAR"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -421,7 +421,7 @@ func TestUint64FlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestUint64FlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestUint64FlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_BAR", "2")
|
_ = os.Setenv("APP_BAR", "2")
|
||||||
for _, test := range uint64FlagTests {
|
for _, test := range uint64FlagTests {
|
||||||
flag := UintFlag{Name: test.name, EnvVar: "APP_BAR"}
|
flag := UintFlag{Name: test.name, EnvVar: "APP_BAR"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -457,7 +457,7 @@ func TestDurationFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_BAR", "2h3m6s")
|
_ = os.Setenv("APP_BAR", "2h3m6s")
|
||||||
for _, test := range durationFlagTests {
|
for _, test := range durationFlagTests {
|
||||||
flag := DurationFlag{Name: test.name, EnvVar: "APP_BAR"}
|
flag := DurationFlag{Name: test.name, EnvVar: "APP_BAR"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -481,8 +481,8 @@ var intSliceFlagTests = []struct {
|
|||||||
{"H", &IntSlice{}, "-H value\t"},
|
{"H", &IntSlice{}, "-H value\t"},
|
||||||
{"H, heads", func() *IntSlice {
|
{"H, heads", func() *IntSlice {
|
||||||
i := &IntSlice{}
|
i := &IntSlice{}
|
||||||
i.Set("9")
|
_ = i.Set("9")
|
||||||
i.Set("3")
|
_ = i.Set("3")
|
||||||
return i
|
return i
|
||||||
}(), "-H value, --heads value\t(default: 9, 3)"},
|
}(), "-H value, --heads value\t(default: 9, 3)"},
|
||||||
}
|
}
|
||||||
@ -500,7 +500,7 @@ func TestIntSliceFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
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, Value: test.value, EnvVar: "APP_SMURF"}
|
flag := IntSliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_SMURF"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -524,8 +524,8 @@ var int64SliceFlagTests = []struct {
|
|||||||
{"H", &Int64Slice{}, "-H value\t"},
|
{"H", &Int64Slice{}, "-H value\t"},
|
||||||
{"H, heads", func() *Int64Slice {
|
{"H, heads", func() *Int64Slice {
|
||||||
i := &Int64Slice{}
|
i := &Int64Slice{}
|
||||||
i.Set("2")
|
_ = i.Set("2")
|
||||||
i.Set("17179869184")
|
_ = i.Set("17179869184")
|
||||||
return i
|
return i
|
||||||
}(), "-H value, --heads value\t(default: 2, 17179869184)"},
|
}(), "-H value, --heads value\t(default: 2, 17179869184)"},
|
||||||
}
|
}
|
||||||
@ -543,7 +543,7 @@ func TestInt64SliceFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestInt64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestInt64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
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, EnvVar: "APP_SMURF"}
|
flag := Int64SliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_SMURF"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -568,7 +568,7 @@ var float64FlagTests = []struct {
|
|||||||
|
|
||||||
func TestFloat64FlagHelpOutput(t *testing.T) {
|
func TestFloat64FlagHelpOutput(t *testing.T) {
|
||||||
for _, test := range float64FlagTests {
|
for _, test := range float64FlagTests {
|
||||||
flag := Float64Flag{Name: test.name, Value: float64(0.1)}
|
flag := Float64Flag{Name: test.name, Value: 0.1}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
|
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
@ -579,7 +579,7 @@ func TestFloat64FlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
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, EnvVar: "APP_BAZ"}
|
flag := Float64Flag{Name: test.name, EnvVar: "APP_BAZ"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -616,7 +616,7 @@ func TestGenericFlagHelpOutput(t *testing.T) {
|
|||||||
|
|
||||||
func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_ZAP", "3")
|
_ = os.Setenv("APP_ZAP", "3")
|
||||||
for _, test := range genericFlagTests {
|
for _, test := range genericFlagTests {
|
||||||
flag := GenericFlag{Name: test.name, EnvVar: "APP_ZAP"}
|
flag := GenericFlag{Name: test.name, EnvVar: "APP_ZAP"}
|
||||||
output := flag.String()
|
output := flag.String()
|
||||||
@ -632,7 +632,7 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiString(t *testing.T) {
|
func TestParseMultiString(t *testing.T) {
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
StringFlag{Name: "serve, s"},
|
StringFlag{Name: "serve, s"},
|
||||||
},
|
},
|
||||||
@ -650,7 +650,7 @@ func TestParseMultiString(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseDestinationString(t *testing.T) {
|
func TestParseDestinationString(t *testing.T) {
|
||||||
var dest string
|
var dest string
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
StringFlag{
|
StringFlag{
|
||||||
Name: "dest",
|
Name: "dest",
|
||||||
@ -663,14 +663,13 @@ func TestParseDestinationString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "--dest", "10"})
|
||||||
a.Run([]string{"run", "--dest", "10"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiStringFromEnv(t *testing.T) {
|
func TestParseMultiStringFromEnv(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_COUNT", "20")
|
_ = os.Setenv("APP_COUNT", "20")
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
StringFlag{Name: "count, c", EnvVar: "APP_COUNT"},
|
StringFlag{Name: "count, c", EnvVar: "APP_COUNT"},
|
||||||
},
|
},
|
||||||
@ -688,8 +687,8 @@ func TestParseMultiStringFromEnv(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseMultiStringFromEnvCascade(t *testing.T) {
|
func TestParseMultiStringFromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_COUNT", "20")
|
_ = os.Setenv("APP_COUNT", "20")
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
StringFlag{Name: "count, c", EnvVar: "COMPAT_COUNT,APP_COUNT"},
|
StringFlag{Name: "count, c", EnvVar: "COMPAT_COUNT,APP_COUNT"},
|
||||||
},
|
},
|
||||||
@ -706,7 +705,7 @@ func TestParseMultiStringFromEnvCascade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiStringSlice(t *testing.T) {
|
func TestParseMultiStringSlice(t *testing.T) {
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
StringSliceFlag{Name: "serve, s", Value: &StringSlice{}},
|
StringSliceFlag{Name: "serve, s", Value: &StringSlice{}},
|
||||||
},
|
},
|
||||||
@ -724,9 +723,9 @@ func TestParseMultiStringSlice(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseMultiStringSliceFromEnv(t *testing.T) {
|
func TestParseMultiStringSliceFromEnv(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_INTERVALS", "20,30,40")
|
_ = os.Setenv("APP_INTERVALS", "20,30,40")
|
||||||
|
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
StringSliceFlag{Name: "intervals, i", Value: &StringSlice{}, EnvVar: "APP_INTERVALS"},
|
StringSliceFlag{Name: "intervals, i", Value: &StringSlice{}, EnvVar: "APP_INTERVALS"},
|
||||||
},
|
},
|
||||||
@ -744,9 +743,9 @@ func TestParseMultiStringSliceFromEnv(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseMultiStringSliceFromEnvCascade(t *testing.T) {
|
func TestParseMultiStringSliceFromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_INTERVALS", "20,30,40")
|
_ = os.Setenv("APP_INTERVALS", "20,30,40")
|
||||||
|
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
StringSliceFlag{Name: "intervals, i", Value: &StringSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
StringSliceFlag{Name: "intervals, i", Value: &StringSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
||||||
},
|
},
|
||||||
@ -763,7 +762,7 @@ func TestParseMultiStringSliceFromEnvCascade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiInt(t *testing.T) {
|
func TestParseMultiInt(t *testing.T) {
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
IntFlag{Name: "serve, s"},
|
IntFlag{Name: "serve, s"},
|
||||||
},
|
},
|
||||||
@ -776,13 +775,12 @@ func TestParseMultiInt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "-s", "10"})
|
||||||
a.Run([]string{"run", "-s", "10"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseDestinationInt(t *testing.T) {
|
func TestParseDestinationInt(t *testing.T) {
|
||||||
var dest int
|
var dest int
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
IntFlag{
|
IntFlag{
|
||||||
Name: "dest",
|
Name: "dest",
|
||||||
@ -795,14 +793,13 @@ func TestParseDestinationInt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "--dest", "10"})
|
||||||
a.Run([]string{"run", "--dest", "10"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiIntFromEnv(t *testing.T) {
|
func TestParseMultiIntFromEnv(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_TIMEOUT_SECONDS", "10")
|
_ = os.Setenv("APP_TIMEOUT_SECONDS", "10")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
IntFlag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
IntFlag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
||||||
},
|
},
|
||||||
@ -815,14 +812,13 @@ func TestParseMultiIntFromEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiIntFromEnvCascade(t *testing.T) {
|
func TestParseMultiIntFromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_TIMEOUT_SECONDS", "10")
|
_ = os.Setenv("APP_TIMEOUT_SECONDS", "10")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
IntFlag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
IntFlag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
||||||
},
|
},
|
||||||
@ -835,12 +831,11 @@ func TestParseMultiIntFromEnvCascade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiIntSlice(t *testing.T) {
|
func TestParseMultiIntSlice(t *testing.T) {
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
IntSliceFlag{Name: "serve, s", Value: &IntSlice{}},
|
IntSliceFlag{Name: "serve, s", Value: &IntSlice{}},
|
||||||
},
|
},
|
||||||
@ -858,9 +853,9 @@ func TestParseMultiIntSlice(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseMultiIntSliceFromEnv(t *testing.T) {
|
func TestParseMultiIntSliceFromEnv(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_INTERVALS", "20,30,40")
|
_ = os.Setenv("APP_INTERVALS", "20,30,40")
|
||||||
|
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
IntSliceFlag{Name: "intervals, i", Value: &IntSlice{}, EnvVar: "APP_INTERVALS"},
|
IntSliceFlag{Name: "intervals, i", Value: &IntSlice{}, EnvVar: "APP_INTERVALS"},
|
||||||
},
|
},
|
||||||
@ -878,9 +873,9 @@ func TestParseMultiIntSliceFromEnv(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseMultiIntSliceFromEnvCascade(t *testing.T) {
|
func TestParseMultiIntSliceFromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_INTERVALS", "20,30,40")
|
_ = os.Setenv("APP_INTERVALS", "20,30,40")
|
||||||
|
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
IntSliceFlag{Name: "intervals, i", Value: &IntSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
IntSliceFlag{Name: "intervals, i", Value: &IntSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
||||||
},
|
},
|
||||||
@ -897,7 +892,7 @@ func TestParseMultiIntSliceFromEnvCascade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiInt64Slice(t *testing.T) {
|
func TestParseMultiInt64Slice(t *testing.T) {
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
Int64SliceFlag{Name: "serve, s", Value: &Int64Slice{}},
|
Int64SliceFlag{Name: "serve, s", Value: &Int64Slice{}},
|
||||||
},
|
},
|
||||||
@ -915,9 +910,9 @@ func TestParseMultiInt64Slice(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseMultiInt64SliceFromEnv(t *testing.T) {
|
func TestParseMultiInt64SliceFromEnv(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_INTERVALS", "20,30,17179869184")
|
_ = os.Setenv("APP_INTERVALS", "20,30,17179869184")
|
||||||
|
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
Int64SliceFlag{Name: "intervals, i", Value: &Int64Slice{}, EnvVar: "APP_INTERVALS"},
|
Int64SliceFlag{Name: "intervals, i", Value: &Int64Slice{}, EnvVar: "APP_INTERVALS"},
|
||||||
},
|
},
|
||||||
@ -935,9 +930,9 @@ func TestParseMultiInt64SliceFromEnv(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseMultiInt64SliceFromEnvCascade(t *testing.T) {
|
func TestParseMultiInt64SliceFromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_INTERVALS", "20,30,17179869184")
|
_ = os.Setenv("APP_INTERVALS", "20,30,17179869184")
|
||||||
|
|
||||||
(&App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
Int64SliceFlag{Name: "intervals, i", Value: &Int64Slice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
Int64SliceFlag{Name: "intervals, i", Value: &Int64Slice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
||||||
},
|
},
|
||||||
@ -954,7 +949,7 @@ func TestParseMultiInt64SliceFromEnvCascade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiFloat64(t *testing.T) {
|
func TestParseMultiFloat64(t *testing.T) {
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
Float64Flag{Name: "serve, s"},
|
Float64Flag{Name: "serve, s"},
|
||||||
},
|
},
|
||||||
@ -967,13 +962,12 @@ func TestParseMultiFloat64(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "-s", "10.2"})
|
||||||
a.Run([]string{"run", "-s", "10.2"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseDestinationFloat64(t *testing.T) {
|
func TestParseDestinationFloat64(t *testing.T) {
|
||||||
var dest float64
|
var dest float64
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
Float64Flag{
|
Float64Flag{
|
||||||
Name: "dest",
|
Name: "dest",
|
||||||
@ -986,14 +980,13 @@ func TestParseDestinationFloat64(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "--dest", "10.2"})
|
||||||
a.Run([]string{"run", "--dest", "10.2"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiFloat64FromEnv(t *testing.T) {
|
func TestParseMultiFloat64FromEnv(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
_ = os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
||||||
},
|
},
|
||||||
@ -1006,14 +999,13 @@ func TestParseMultiFloat64FromEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiFloat64FromEnvCascade(t *testing.T) {
|
func TestParseMultiFloat64FromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
_ = os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
Float64Flag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
Float64Flag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
||||||
},
|
},
|
||||||
@ -1026,12 +1018,11 @@ func TestParseMultiFloat64FromEnvCascade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiBool(t *testing.T) {
|
func TestParseMultiBool(t *testing.T) {
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolFlag{Name: "serve, s"},
|
BoolFlag{Name: "serve, s"},
|
||||||
},
|
},
|
||||||
@ -1044,15 +1035,14 @@ func TestParseMultiBool(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "--serve"})
|
||||||
a.Run([]string{"run", "--serve"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseBoolShortOptionHandle(t *testing.T) {
|
func TestParseBoolShortOptionHandle(t *testing.T) {
|
||||||
a := App{
|
_ = (&App{
|
||||||
Commands: []Command{
|
Commands: []Command{
|
||||||
{
|
{
|
||||||
Name: "foobar",
|
Name: "foobar",
|
||||||
UseShortOptionHandling: true,
|
UseShortOptionHandling: true,
|
||||||
Action: func(ctx *Context) error {
|
Action: func(ctx *Context) error {
|
||||||
if ctx.Bool("serve") != true {
|
if ctx.Bool("serve") != true {
|
||||||
@ -1069,13 +1059,12 @@ func TestParseBoolShortOptionHandle(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "foobar", "-so"})
|
||||||
a.Run([]string{"run", "foobar", "-so"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseDestinationBool(t *testing.T) {
|
func TestParseDestinationBool(t *testing.T) {
|
||||||
var dest bool
|
var dest bool
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolFlag{
|
BoolFlag{
|
||||||
Name: "dest",
|
Name: "dest",
|
||||||
@ -1088,14 +1077,13 @@ func TestParseDestinationBool(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "--dest"})
|
||||||
a.Run([]string{"run", "--dest"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiBoolFromEnv(t *testing.T) {
|
func TestParseMultiBoolFromEnv(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_DEBUG", "1")
|
_ = os.Setenv("APP_DEBUG", "1")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
BoolFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
||||||
},
|
},
|
||||||
@ -1108,14 +1096,13 @@ func TestParseMultiBoolFromEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiBoolFromEnvCascade(t *testing.T) {
|
func TestParseMultiBoolFromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_DEBUG", "1")
|
os.Setenv("APP_DEBUG", "1")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
BoolFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
||||||
},
|
},
|
||||||
@ -1128,8 +1115,7 @@ func TestParseMultiBoolFromEnvCascade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseBoolTFromEnv(t *testing.T) {
|
func TestParseBoolTFromEnv(t *testing.T) {
|
||||||
@ -1145,8 +1131,8 @@ func TestParseBoolTFromEnv(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range boolTFlagTests {
|
for _, test := range boolTFlagTests {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("DEBUG", test.input)
|
_ = os.Setenv("DEBUG", test.input)
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolTFlag{Name: "debug, d", EnvVar: "DEBUG"},
|
BoolTFlag{Name: "debug, d", EnvVar: "DEBUG"},
|
||||||
},
|
},
|
||||||
@ -1159,13 +1145,12 @@ func TestParseBoolTFromEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiBoolT(t *testing.T) {
|
func TestParseMultiBoolT(t *testing.T) {
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolTFlag{Name: "serve, s"},
|
BoolTFlag{Name: "serve, s"},
|
||||||
},
|
},
|
||||||
@ -1178,13 +1163,12 @@ func TestParseMultiBoolT(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "--serve"})
|
||||||
a.Run([]string{"run", "--serve"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseDestinationBoolT(t *testing.T) {
|
func TestParseDestinationBoolT(t *testing.T) {
|
||||||
var dest bool
|
var dest bool
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolTFlag{
|
BoolTFlag{
|
||||||
Name: "dest",
|
Name: "dest",
|
||||||
@ -1197,14 +1181,13 @@ func TestParseDestinationBoolT(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "--dest"})
|
||||||
a.Run([]string{"run", "--dest"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiBoolTFromEnv(t *testing.T) {
|
func TestParseMultiBoolTFromEnv(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_DEBUG", "0")
|
_ = os.Setenv("APP_DEBUG", "0")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolTFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
BoolTFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
||||||
},
|
},
|
||||||
@ -1217,14 +1200,13 @@ func TestParseMultiBoolTFromEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiBoolTFromEnvCascade(t *testing.T) {
|
func TestParseMultiBoolTFromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_DEBUG", "0")
|
_ = os.Setenv("APP_DEBUG", "0")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
BoolTFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
BoolTFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
||||||
},
|
},
|
||||||
@ -1237,8 +1219,7 @@ func TestParseMultiBoolTFromEnvCascade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Parser [2]string
|
type Parser [2]string
|
||||||
@ -1264,7 +1245,7 @@ func (p *Parser) Get() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseGeneric(t *testing.T) {
|
func TestParseGeneric(t *testing.T) {
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
GenericFlag{Name: "serve, s", Value: &Parser{}},
|
GenericFlag{Name: "serve, s", Value: &Parser{}},
|
||||||
},
|
},
|
||||||
@ -1277,14 +1258,13 @@ func TestParseGeneric(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run", "-s", "10,20"})
|
||||||
a.Run([]string{"run", "-s", "10,20"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseGenericFromEnv(t *testing.T) {
|
func TestParseGenericFromEnv(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_SERVE", "20,30")
|
_ = os.Setenv("APP_SERVE", "20,30")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
GenericFlag{Name: "serve, s", Value: &Parser{}, EnvVar: "APP_SERVE"},
|
GenericFlag{Name: "serve, s", Value: &Parser{}, EnvVar: "APP_SERVE"},
|
||||||
},
|
},
|
||||||
@ -1297,14 +1277,13 @@ func TestParseGenericFromEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseGenericFromEnvCascade(t *testing.T) {
|
func TestParseGenericFromEnvCascade(t *testing.T) {
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
os.Setenv("APP_FOO", "99,2000")
|
_ = os.Setenv("APP_FOO", "99,2000")
|
||||||
a := App{
|
_ = (&App{
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
GenericFlag{Name: "foos", Value: &Parser{}, EnvVar: "COMPAT_FOO,APP_FOO"},
|
GenericFlag{Name: "foos", Value: &Parser{}, EnvVar: "COMPAT_FOO,APP_FOO"},
|
||||||
},
|
},
|
||||||
@ -1314,8 +1293,7 @@ func TestParseGenericFromEnvCascade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}).Run([]string{"run"})
|
||||||
a.Run([]string{"run"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlagFromFile(t *testing.T) {
|
func TestFlagFromFile(t *testing.T) {
|
||||||
@ -1327,10 +1305,10 @@ func TestFlagFromFile(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
io.WriteString(temp, "abc")
|
_, _ = io.WriteString(temp, "abc")
|
||||||
temp.Close()
|
_ = temp.Close()
|
||||||
defer func() {
|
defer func() {
|
||||||
os.Remove(temp.Name())
|
_ = os.Remove(temp.Name())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var filePathTests = []struct {
|
var filePathTests = []struct {
|
||||||
|
22
help.go
22
help.go
@ -94,7 +94,7 @@ var helpCommand = Command{
|
|||||||
return ShowCommandHelp(c, args.First())
|
return ShowCommandHelp(c, args.First())
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowAppHelp(c)
|
_ = ShowAppHelp(c)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ var VersionPrinter = printVersion
|
|||||||
|
|
||||||
// ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code.
|
// ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code.
|
||||||
func ShowAppHelpAndExit(c *Context, exitCode int) {
|
func ShowAppHelpAndExit(c *Context, exitCode int) {
|
||||||
ShowAppHelp(c)
|
_ = ShowAppHelp(c)
|
||||||
os.Exit(exitCode)
|
os.Exit(exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,11 +168,11 @@ func printCommandSuggestions(commands []Command, writer io.Writer) {
|
|||||||
}
|
}
|
||||||
if os.Getenv("_CLI_ZSH_AUTOCOMPLETE_HACK") == "1" {
|
if os.Getenv("_CLI_ZSH_AUTOCOMPLETE_HACK") == "1" {
|
||||||
for _, name := range command.Names() {
|
for _, name := range command.Names() {
|
||||||
fmt.Fprintf(writer, "%s:%s\n", name, command.Usage)
|
_, _ = fmt.Fprintf(writer, "%s:%s\n", name, command.Usage)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, name := range command.Names() {
|
for _, name := range command.Names() {
|
||||||
fmt.Fprintf(writer, "%s\n", name)
|
_, _ = fmt.Fprintf(writer, "%s\n", name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) {
|
|||||||
// match if last argument matches this flag and it is not repeated
|
// match if last argument matches this flag and it is not repeated
|
||||||
if strings.HasPrefix(name, cur) && cur != name && !cliArgContains(flag.GetName()) {
|
if strings.HasPrefix(name, cur) && cur != name && !cliArgContains(flag.GetName()) {
|
||||||
flagCompletion := fmt.Sprintf("%s%s", strings.Repeat("-", count), name)
|
flagCompletion := fmt.Sprintf("%s%s", strings.Repeat("-", count), name)
|
||||||
fmt.Fprintln(writer, flagCompletion)
|
_, _ = fmt.Fprintln(writer, flagCompletion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ func DefaultCompleteWithFlags(cmd *Command) func(c *Context) {
|
|||||||
|
|
||||||
// ShowCommandHelpAndExit - exits with code after showing help
|
// ShowCommandHelpAndExit - exits with code after showing help
|
||||||
func ShowCommandHelpAndExit(c *Context, command string, code int) {
|
func ShowCommandHelpAndExit(c *Context, command string, code int) {
|
||||||
ShowCommandHelp(c, command)
|
_ = ShowCommandHelp(c, command)
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ func ShowVersion(c *Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printVersion(c *Context) {
|
func printVersion(c *Context) {
|
||||||
fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version)
|
_, _ = fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowCompletions prints the lists of commands within a given context
|
// ShowCompletions prints the lists of commands within a given context
|
||||||
@ -326,11 +326,11 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc m
|
|||||||
// If the writer is closed, t.Execute will fail, and there's nothing
|
// If the writer is closed, t.Execute will fail, and there's nothing
|
||||||
// we can do to recover.
|
// we can do to recover.
|
||||||
if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" {
|
if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" {
|
||||||
fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err)
|
_, _ = fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Flush()
|
_ = w.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func printHelp(out io.Writer, templ string, data interface{}) {
|
func printHelp(out io.Writer, templ string, data interface{}) {
|
||||||
@ -363,7 +363,7 @@ func checkHelp(c *Context) bool {
|
|||||||
|
|
||||||
func checkCommandHelp(c *Context, name string) bool {
|
func checkCommandHelp(c *Context, name string) bool {
|
||||||
if c.Bool("h") || c.Bool("help") {
|
if c.Bool("h") || c.Bool("help") {
|
||||||
ShowCommandHelp(c, name)
|
_ = ShowCommandHelp(c, name)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,7 +372,7 @@ func checkCommandHelp(c *Context, name string) bool {
|
|||||||
|
|
||||||
func checkSubcommandHelp(c *Context) bool {
|
func checkSubcommandHelp(c *Context) bool {
|
||||||
if c.Bool("h") || c.Bool("help") {
|
if c.Bool("h") || c.Bool("help") {
|
||||||
ShowSubcommandHelp(c)
|
_ = ShowSubcommandHelp(c)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
help_test.go
38
help_test.go
@ -16,9 +16,9 @@ func Test_ShowAppHelp_NoAuthor(t *testing.T) {
|
|||||||
|
|
||||||
c := NewContext(app, nil, nil)
|
c := NewContext(app, nil, nil)
|
||||||
|
|
||||||
ShowAppHelp(c)
|
_ = ShowAppHelp(c)
|
||||||
|
|
||||||
if bytes.Index(output.Bytes(), []byte("AUTHOR(S):")) != -1 {
|
if bytes.Contains(output.Bytes(), []byte("AUTHOR(S):")) {
|
||||||
t.Errorf("expected\n%snot to include %s", output.String(), "AUTHOR(S):")
|
t.Errorf("expected\n%snot to include %s", output.String(), "AUTHOR(S):")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,9 +32,9 @@ func Test_ShowAppHelp_NoVersion(t *testing.T) {
|
|||||||
|
|
||||||
c := NewContext(app, nil, nil)
|
c := NewContext(app, nil, nil)
|
||||||
|
|
||||||
ShowAppHelp(c)
|
_ = ShowAppHelp(c)
|
||||||
|
|
||||||
if bytes.Index(output.Bytes(), []byte("VERSION:")) != -1 {
|
if bytes.Contains(output.Bytes(), []byte("VERSION:")) {
|
||||||
t.Errorf("expected\n%snot to include %s", output.String(), "VERSION:")
|
t.Errorf("expected\n%snot to include %s", output.String(), "VERSION:")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,9 +48,9 @@ func Test_ShowAppHelp_HideVersion(t *testing.T) {
|
|||||||
|
|
||||||
c := NewContext(app, nil, nil)
|
c := NewContext(app, nil, nil)
|
||||||
|
|
||||||
ShowAppHelp(c)
|
_ = ShowAppHelp(c)
|
||||||
|
|
||||||
if bytes.Index(output.Bytes(), []byte("VERSION:")) != -1 {
|
if bytes.Contains(output.Bytes(), []byte("VERSION:")) {
|
||||||
t.Errorf("expected\n%snot to include %s", output.String(), "VERSION:")
|
t.Errorf("expected\n%snot to include %s", output.String(), "VERSION:")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func Test_Help_Custom_Flags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
output := new(bytes.Buffer)
|
output := new(bytes.Buffer)
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"test", "-h"})
|
_ = app.Run([]string{"test", "-h"})
|
||||||
if output.Len() > 0 {
|
if output.Len() > 0 {
|
||||||
t.Errorf("unexpected output: %s", output.String())
|
t.Errorf("unexpected output: %s", output.String())
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ func Test_Version_Custom_Flags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
output := new(bytes.Buffer)
|
output := new(bytes.Buffer)
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"test", "-v"})
|
_ = app.Run([]string{"test", "-v"})
|
||||||
if output.Len() > 0 {
|
if output.Len() > 0 {
|
||||||
t.Errorf("unexpected output: %s", output.String())
|
t.Errorf("unexpected output: %s", output.String())
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func Test_helpCommand_Action_ErrorIfNoTopic(t *testing.T) {
|
|||||||
app := NewApp()
|
app := NewApp()
|
||||||
|
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
set.Parse([]string{"foo"})
|
_ = set.Parse([]string{"foo"})
|
||||||
|
|
||||||
c := NewContext(app, set, nil)
|
c := NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ func Test_helpCommand_InHelpOutput(t *testing.T) {
|
|||||||
app := NewApp()
|
app := NewApp()
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"test", "--help"})
|
_ = app.Run([]string{"test", "--help"})
|
||||||
|
|
||||||
s := output.String()
|
s := output.String()
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ func Test_helpSubcommand_Action_ErrorIfNoTopic(t *testing.T) {
|
|||||||
app := NewApp()
|
app := NewApp()
|
||||||
|
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
set.Parse([]string{"foo"})
|
_ = set.Parse([]string{"foo"})
|
||||||
|
|
||||||
c := NewContext(app, set, nil)
|
c := NewContext(app, set, nil)
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ func TestShowAppHelp_CommandAliases(t *testing.T) {
|
|||||||
|
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"foo", "--help"})
|
_ = app.Run([]string{"foo", "--help"})
|
||||||
|
|
||||||
if !strings.Contains(output.String(), "frobbly, fr, frob") {
|
if !strings.Contains(output.String(), "frobbly, fr, frob") {
|
||||||
t.Errorf("expected output to include all command aliases; got: %q", output.String())
|
t.Errorf("expected output to include all command aliases; got: %q", output.String())
|
||||||
@ -225,7 +225,7 @@ func TestShowCommandHelp_CommandAliases(t *testing.T) {
|
|||||||
|
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"foo", "help", "fr"})
|
_ = app.Run([]string{"foo", "help", "fr"})
|
||||||
|
|
||||||
if !strings.Contains(output.String(), "frobbly") {
|
if !strings.Contains(output.String(), "frobbly") {
|
||||||
t.Errorf("expected output to include command name; got: %q", output.String())
|
t.Errorf("expected output to include command name; got: %q", output.String())
|
||||||
@ -251,7 +251,7 @@ func TestShowSubcommandHelp_CommandAliases(t *testing.T) {
|
|||||||
|
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"foo", "help"})
|
_ = app.Run([]string{"foo", "help"})
|
||||||
|
|
||||||
if !strings.Contains(output.String(), "frobbly, fr, frob, bork") {
|
if !strings.Contains(output.String(), "frobbly, fr, frob, bork") {
|
||||||
t.Errorf("expected output to include all command aliases; got: %q", output.String())
|
t.Errorf("expected output to include all command aliases; got: %q", output.String())
|
||||||
@ -285,7 +285,7 @@ EXAMPLES:
|
|||||||
}
|
}
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"foo", "help", "frobbly"})
|
_ = app.Run([]string{"foo", "help", "frobbly"})
|
||||||
|
|
||||||
if strings.Contains(output.String(), "2. Frobbly runs without this param locally.") {
|
if strings.Contains(output.String(), "2. Frobbly runs without this param locally.") {
|
||||||
t.Errorf("expected output to exclude \"2. Frobbly runs without this param locally.\"; got: %q", output.String())
|
t.Errorf("expected output to exclude \"2. Frobbly runs without this param locally.\"; got: %q", output.String())
|
||||||
@ -313,7 +313,7 @@ func TestShowSubcommandHelp_CommandUsageText(t *testing.T) {
|
|||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
|
|
||||||
app.Run([]string{"foo", "frobbly", "--help"})
|
_ = app.Run([]string{"foo", "frobbly", "--help"})
|
||||||
|
|
||||||
if !strings.Contains(output.String(), "this is usage text") {
|
if !strings.Contains(output.String(), "this is usage text") {
|
||||||
t.Errorf("expected output to include usage text; got: %q", output.String())
|
t.Errorf("expected output to include usage text; got: %q", output.String())
|
||||||
@ -337,7 +337,7 @@ func TestShowSubcommandHelp_SubcommandUsageText(t *testing.T) {
|
|||||||
|
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"foo", "frobbly", "bobbly", "--help"})
|
_ = app.Run([]string{"foo", "frobbly", "bobbly", "--help"})
|
||||||
|
|
||||||
if !strings.Contains(output.String(), "this is usage text") {
|
if !strings.Contains(output.String(), "this is usage text") {
|
||||||
t.Errorf("expected output to include usage text; got: %q", output.String())
|
t.Errorf("expected output to include usage text; got: %q", output.String())
|
||||||
@ -365,7 +365,7 @@ func TestShowAppHelp_HiddenCommand(t *testing.T) {
|
|||||||
|
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"app", "--help"})
|
_ = app.Run([]string{"app", "--help"})
|
||||||
|
|
||||||
if strings.Contains(output.String(), "secretfrob") {
|
if strings.Contains(output.String(), "secretfrob") {
|
||||||
t.Errorf("expected output to exclude \"secretfrob\"; got: %q", output.String())
|
t.Errorf("expected output to exclude \"secretfrob\"; got: %q", output.String())
|
||||||
@ -423,7 +423,7 @@ VERSION:
|
|||||||
|
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
app.Writer = output
|
app.Writer = output
|
||||||
app.Run([]string{"app", "--help"})
|
_ = app.Run([]string{"app", "--help"})
|
||||||
|
|
||||||
if strings.Contains(output.String(), "secretfrob") {
|
if strings.Contains(output.String(), "secretfrob") {
|
||||||
t.Errorf("expected output to exclude \"secretfrob\"; got: %q", output.String())
|
t.Errorf("expected output to exclude \"secretfrob\"; got: %q", output.String())
|
||||||
|
Loading…
Reference in New Issue
Block a user