make cmd.Run use varargs
This commit is contained in:
parent
adcce134f3
commit
59095aa762
@ -46,7 +46,7 @@ func TestCommandJSONFileTest(t *testing.T) {
|
||||
},
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -81,7 +81,7 @@ func TestCommandJSONFileTestGlobalEnvVarWins(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -116,7 +116,7 @@ func TestCommandJSONFileTestGlobalEnvVarWinsNested(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -148,7 +148,7 @@ func TestCommandJSONFileTestSpecifiedFlagWins(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -180,7 +180,7 @@ func TestCommandJSONFileTestSpecifiedFlagWinsNested(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -212,7 +212,7 @@ func TestCommandJSONFileTestDefaultValueFileWins(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -244,7 +244,7 @@ func TestCommandJSONFileTestDefaultValueFileWinsNested(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -278,7 +278,7 @@ func TestCommandJSONFileFlagHasDefaultGlobalEnvJSONSetGlobalEnvWins(t *testing.T
|
||||
&cli.StringFlag{Name: "load"}},
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -312,7 +312,7 @@ func TestCommandJSONFileFlagHasDefaultGlobalEnvJSONSetGlobalEnvWinsNested(t *tes
|
||||
&cli.StringFlag{Name: "load"}},
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func TestCommandTomFileTest(t *testing.T) {
|
||||
&cli.StringFlag{Name: "load"}},
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewTomlSourceFromFlagFunc("load"))
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -68,7 +68,7 @@ func TestCommandTomlFileTestGlobalEnvVarWins(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewTomlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -102,7 +102,7 @@ func TestCommandTomlFileTestGlobalEnvVarWinsNested(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewTomlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -134,7 +134,7 @@ func TestCommandTomlFileTestSpecifiedFlagWins(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewTomlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -167,7 +167,7 @@ func TestCommandTomlFileTestSpecifiedFlagWinsNested(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewTomlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -199,7 +199,7 @@ func TestCommandTomlFileTestDefaultValueFileWins(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewTomlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -231,7 +231,7 @@ func TestCommandTomlFileTestDefaultValueFileWinsNested(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewTomlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -265,7 +265,7 @@ func TestCommandTomlFileFlagHasDefaultGlobalEnvTomlSetGlobalEnvWins(t *testing.T
|
||||
&cli.StringFlag{Name: "load"}},
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewTomlSourceFromFlagFunc("load"))
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -299,7 +299,7 @@ func TestCommandTomlFileFlagHasDefaultGlobalEnvTomlSetGlobalEnvWinsNested(t *tes
|
||||
&cli.StringFlag{Name: "load"}},
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewTomlSourceFromFlagFunc("load"))
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func TestCommandYamlFileTest(t *testing.T) {
|
||||
&cli.StringFlag{Name: "load"}},
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -68,7 +68,7 @@ func TestCommandYamlFileTestGlobalEnvVarWins(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -103,7 +103,7 @@ func TestCommandYamlFileTestGlobalEnvVarWinsNested(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -135,7 +135,7 @@ func TestCommandYamlFileTestSpecifiedFlagWins(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -168,7 +168,7 @@ func TestCommandYamlFileTestSpecifiedFlagWinsNested(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -200,7 +200,7 @@ func TestCommandYamlFileTestDefaultValueFileWins(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -233,7 +233,7 @@ func TestCommandYamlFileTestDefaultValueFileWinsNested(t *testing.T) {
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
|
||||
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -267,7 +267,7 @@ func TestCommandYamlFileFlagHasDefaultGlobalEnvYamlSetGlobalEnvWins(t *testing.T
|
||||
&cli.StringFlag{Name: "load"}},
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
@ -302,7 +302,7 @@ func TestCommandYamlFileFlagHasDefaultGlobalEnvYamlSetGlobalEnvWinsNested(t *tes
|
||||
&cli.StringFlag{Name: "load"}},
|
||||
}
|
||||
command.Before = InitInputSourceWithContext(command.Flags, NewYamlSourceFromFlagFunc("load"))
|
||||
err := command.Run(c, test)
|
||||
err := command.Run(c, test...)
|
||||
|
||||
expect(t, err, nil)
|
||||
}
|
||||
|
2
app.go
2
app.go
@ -275,7 +275,7 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
|
||||
a.rootCommand = newRootCommand(a)
|
||||
cCtx.Command = a.rootCommand
|
||||
|
||||
return a.rootCommand.Run(cCtx, arguments)
|
||||
return a.rootCommand.Run(cCtx, arguments...)
|
||||
}
|
||||
|
||||
func (a *App) suggestFlagFromError(err error, command string) (string, error) {
|
||||
|
@ -163,7 +163,7 @@ func (c *Command) setup(ctx *Context) {
|
||||
c.Subcommands = newCmds
|
||||
}
|
||||
|
||||
func (c *Command) Run(cCtx *Context, arguments []string) (err error) {
|
||||
func (c *Command) Run(cCtx *Context, arguments ...string) (err error) {
|
||||
|
||||
if !c.isRoot {
|
||||
c.setup(cCtx)
|
||||
@ -286,7 +286,7 @@ func (c *Command) Run(cCtx *Context, arguments []string) (err error) {
|
||||
if cmd != nil {
|
||||
newcCtx := NewContext(cCtx.App, nil, cCtx)
|
||||
newcCtx.Command = cmd
|
||||
return cmd.Run(newcCtx, cCtx.Args().Slice())
|
||||
return cmd.Run(newcCtx, cCtx.Args().Slice()...)
|
||||
}
|
||||
|
||||
if c.Action == nil {
|
||||
|
@ -43,7 +43,7 @@ func TestCommandFlagParsing(t *testing.T) {
|
||||
isRoot: true,
|
||||
}
|
||||
|
||||
err := command.Run(cCtx, c.testArgs)
|
||||
err := command.Run(cCtx, c.testArgs...)
|
||||
|
||||
expect(t, err, c.expectedErr)
|
||||
//expect(t, cCtx.Args().Slice(), c.testArgs)
|
||||
|
@ -566,7 +566,7 @@ func (c *Command) HasName(name string) bool
|
||||
func (c *Command) Names() []string
|
||||
Names returns the names including short names and aliases.
|
||||
|
||||
func (c *Command) Run(cCtx *Context, arguments []string) (err error)
|
||||
func (c *Command) Run(cCtx *Context, arguments ...string) (err error)
|
||||
|
||||
func (c *Command) VisibleCategories() []CommandCategory
|
||||
VisibleCategories returns a slice of categories and commands that are
|
||||
|
2
testdata/godoc-v2.x.txt
vendored
2
testdata/godoc-v2.x.txt
vendored
@ -566,7 +566,7 @@ func (c *Command) HasName(name string) bool
|
||||
func (c *Command) Names() []string
|
||||
Names returns the names including short names and aliases.
|
||||
|
||||
func (c *Command) Run(cCtx *Context, arguments []string) (err error)
|
||||
func (c *Command) Run(cCtx *Context, arguments ...string) (err error)
|
||||
|
||||
func (c *Command) VisibleCategories() []CommandCategory
|
||||
VisibleCategories returns a slice of categories and commands that are
|
||||
|
Loading…
Reference in New Issue
Block a user