Skip to content

Commit a2ea361

Browse files
committed
Fix unknown command error message
1 parent 07f92dd commit a2ea361

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

‎simplecobra.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func checkArgs(cmd *cobra.Command, args []string) error {
233233
return nil
234234
}
235235

236-
return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), findSuggestions(cmd, commandName))
236+
return fmt.Errorf("unknown command %q for %q%s", args[1], cmd.CommandPath(), findSuggestions(cmd, commandName))
237237
}
238238

239239
func findSuggestions(cmd *cobra.Command, arg string) string {

‎simplecobra_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestErrors(t *testing.T) {
107107
c.Assert(err, qt.IsNil)
108108
_, err = x.Execute(context.Background(), []string{"fooo"})
109109
c.Assert(err, qt.Not(qt.IsNil))
110-
c.Assert(err.Error(), qt.Contains, "unknown")
110+
c.Assert(err.Error(), qt.Contains, "unknown command \"fooo\"")
111111
c.Assert(err.Error(), qt.Contains, "Did you mean this?")
112112
c.Assert(simplecobra.IsCommandError(err), qt.Equals, true)
113113
})
@@ -136,7 +136,7 @@ func TestErrors(t *testing.T) {
136136
c.Assert(err, qt.IsNil)
137137
_, err = x.Execute(context.Background(), []string{"foo", "bars"})
138138
c.Assert(err, qt.Not(qt.IsNil))
139-
c.Assert(err.Error(), qt.Contains, "unknown")
139+
c.Assert(err.Error(), qt.Contains, `command error: unknown command "bars" for "root foo"`)
140140
c.Assert(err.Error(), qt.Not(qt.Contains), "Did you mean this?")
141141
})
142142

0 commit comments

Comments
 (0)