diff --git a/application.go b/application.go index 5481672..5b1a9ce 100644 --- a/application.go +++ b/application.go @@ -152,7 +152,8 @@ func (a *Application) Run(arguments []string) (err error) { return err } -// Command returns the named command on App. Returns nil if the command does not exist +// Command returns the named command on App. Returns nil if the command does not +// exist func (a *Application) Command(name string) *Command { for _, c := range a.Commands { if c.HasName(name, true) { @@ -163,8 +164,9 @@ func (a *Application) Command(name string) *Command { return nil } -// BestCommand returns the named command on App or there is exactly one command the fuzzy matches. -// Returns nil if the command does not exist +// BestCommand returns the named command on App or a command fuzzy matching if +// there is only one. Returns nil if the command does not exist of if the fuzzy +// matching find more than one. func (a *Application) BestCommand(name string) *Command { if c := a.Command(name); c != nil { return c diff --git a/command_test.go b/command_test.go index 6d07bcf..4225d02 100644 --- a/command_test.go +++ b/command_test.go @@ -121,28 +121,28 @@ func TestFuzzyCommandNames(t *testing.T) { projectLink, } - c := app.Command("project:list") + c := app.BestCommand("project:list") if c != projectList { - t.Fatalf("expected project:list, got %s", c.Name) + t.Fatalf("expected project:list, got %v", c) } - c = app.Command("project:link") + c = app.BestCommand("project:link") if c != projectLink { - t.Fatalf("expected project:link, got %s", c.Name) + t.Fatalf("expected project:link, got %v", c) } - c = app.Command("pro:list") + c = app.BestCommand("pro:list") if c != projectList { - t.Fatalf("expected project:list, got %s", c.Name) + t.Fatalf("expected project:list, got %v", c) } - c = app.Command("pro:lis") + c = app.BestCommand("pro:lis") if c != projectList { - t.Fatalf("expected project:list, got %s", c.Name) + t.Fatalf("expected project:list, got %v", c) } - c = app.Command("p:lis") + c = app.BestCommand("p:lis") if c != projectList { - t.Fatalf("expected project:list, got %s", c.Name) + t.Fatalf("expected project:list, got %v", c) } - c = app.Command("p:li") + c = app.BestCommand("p:li") if c != nil { - t.Fatalf("expected no matches, got %s", c.Name) + t.Fatalf("expected no matches, got %v", c) } }