Skip to content

Commit

Permalink
Fix TestFuzzyCommandNames tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tucksaun committed Sep 7, 2023
1 parent c00f353 commit 38ba11b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 38ba11b

Please sign in to comment.