Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed app methods Run and RunArgs to Parse and ParseArgs. #3

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func NewApp(name, brief string) *App {
return &app
}

// Run runs the parser, collecting the values from the command-line
// Parse runs the parser, collecting the values from the command-line
// and running any needed subcommands.
func (app *App) Run() error {
return app.RunArgs(os.Args[1:])
func (app *App) Parse() error {
return app.ParseArgs(os.Args[1:])
}

// RunArgs behave like run, but instead of looking to the command-line
// ParseArgs behave like parse, but instead of looking to the command-line
// arguments, it takes an array of arguments as parameters.
func (app *App) RunArgs(args []string) error {
func (app *App) ParseArgs(args []string) error {
return app.doRun(args)
}
10 changes: 5 additions & 5 deletions cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestSubCommand(t *testing.T) {
c2 = true
})

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error running parser: %v", i, err)
continue
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestCommandArgReuse(t *testing.T) {
})
})

err := app.RunArgs(test.cmd)
err := app.ParseArgs(test.cmd)
if test.expectError && !libcmd.IsParserErr(err) {
t.Errorf("Case %d, should have returned error", i)
continue
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestCommandArgSameName(t *testing.T) {
})
})

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error running parser: %v", i, err)
continue
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestRun(t *testing.T) {
})
})

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error running parser: %v", i, err)
continue
}
Expand All @@ -285,7 +285,7 @@ func TestNoMatch(t *testing.T) {
c1 = true
})

if err := app.RunArgs([]string{"", ""}); err != nil {
if err := app.ParseArgs([]string{"", ""}); err != nil {
t.Errorf("Error running parser: %v", err)
return
}
Expand Down
6 changes: 3 additions & 3 deletions get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestGet(t *testing.T) {
app.Float32("afloat32", "f32", 0, "specifies a float32 value")
app.Float64("afloat64", "f64", 0, "specifies a float64 value")

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestGetIntLimit(t *testing.T) {
app.Uint32("", "g", 0, "specifies a uint32 value")
app.Uint64("", "h", 0, "specifies a uint64 value")

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestGetChoice(t *testing.T) {
app := libcmd.NewApp("", "")
app.Choice([]string{"foo", "bar", "baz"}, "", "c", "", "")

err := app.RunArgs(test.cmd)
err := app.ParseArgs(test.cmd)
if !test.expectErr && err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
Expand Down
2 changes: 1 addition & 1 deletion help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func compareHelpOutput(app *libcmd.App, args []string, goldenfile string) error

if len(args) == 0 {
app.Help()
} else if err := app.RunArgs(args); err != nil {
} else if err := app.ParseArgs(args); err != nil {
return err
}

Expand Down
20 changes: 10 additions & 10 deletions opt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestOpt(t *testing.T) {
afloat32 := app.Float32("afloat32", "f32", 0, "specifies a float32 value")
afloat64 := app.Float64("afloat64", "f64", 0, "specifies a float64 value")

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestOptDefault(t *testing.T) {
afloat32 := app.Float32("afloat32", "f32", float32(3.14), "specifies a float32 value")
afloat64 := app.Float64("afloat64", "f64", float64(3.1415), "specifies a float64 value")

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestOptError(t *testing.T) {
app.Uint("auint", "u", 0, "specifies an uint value")
app.String("astring", "s", "", "specifies a string value")

err := app.RunArgs(test.cmd)
err := app.ParseArgs(test.cmd)

if err == nil {
t.Errorf("Case %d, argument parsing should return error", i)
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestOptIntLimit(t *testing.T) {
c := app.Int32("", "c", 0, "specifies a int32 value")
d := app.Int64("", "d", 0, "specifies a int64 value")

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
}
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestOptUintLimit(t *testing.T) {
c := app.Uint32("", "c", 0, "specifies a uint32 value")
d := app.Uint64("", "d", 0, "specifies a uint64 value")

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
}
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestOptIntegerLimits(t *testing.T) {
app.Uint32("auint32", "", 0, "specifies a uint32 value")
app.Uint64("auint64", "", 0, "specifies a uint64 value")

err := app.RunArgs(test.cmd)
err := app.ParseArgs(test.cmd)

if err == nil {
t.Errorf("Case %d, argument parsing should return error", i)
Expand Down Expand Up @@ -334,7 +334,7 @@ func TestOptKeepValue(t *testing.T) {
*s1 = keep
*s2 = ""

if err := app.RunArgs(test.cmd); err != nil {
if err := app.ParseArgs(test.cmd); err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
}
Expand All @@ -361,7 +361,7 @@ func TestChoice(t *testing.T) {
app := libcmd.NewApp("", "")
s := app.Choice([]string{"foo", "bar", "baz"}, "", "c", "", "")

err := app.RunArgs(test.cmd)
err := app.ParseArgs(test.cmd)
if !test.expectErr && err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestOperand(t *testing.T) {
s := app.String("", "s", "", "")
app.AddOperand("name", "")

err := app.RunArgs(test.cmd)
err := app.ParseArgs(test.cmd)
if !test.expectErr && err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
Expand Down Expand Up @@ -467,7 +467,7 @@ func TestOperandOptional(t *testing.T) {
app.AddOperand("name", "")
app.AddOperand("value", "?")

err := app.RunArgs(test.cmd)
err := app.ParseArgs(test.cmd)
if !test.expectErr && err != nil {
t.Errorf("Case %d, error parsing args: %v", i, err)
continue
Expand Down