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

Fix TestFuzzyCommandNames tests #6

Merged
merged 2 commits into from
Sep 7, 2023
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
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
24 changes: 12 additions & 12 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}