From 38ba11b0b3f7e521ee4b44e1a9e5518bf7630c37 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Thu, 7 Sep 2023 08:34:39 +0200 Subject: [PATCH] Fix TestFuzzyCommandNames tests --- application.go | 8 +++++--- command_test.go | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) 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 c07813c..4225d02 100644 --- a/command_test.go +++ b/command_test.go @@ -121,27 +121,27 @@ 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 %v", c) } - c = app.Command("project:link") + c = app.BestCommand("project:link") if c != projectLink { 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 %v", c) } - c = app.Command("pro:lis") + c = app.BestCommand("pro:lis") if c != projectList { 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 %v", c) } - c = app.Command("p:li") + c = app.BestCommand("p:li") if c != nil { t.Fatalf("expected no matches, got %v", c) }