Replace prefix matching with aliases
This commit is contained in:
@ -26,9 +26,10 @@ var cmdPrint = &Command{
|
||||
}
|
||||
|
||||
var cmdEcho = &Command{
|
||||
Use: "echo [string to echo]",
|
||||
Short: "Echo anything to the screen",
|
||||
Long: `an utterly useless command for testing.`,
|
||||
Use: "echo [string to echo]",
|
||||
Aliases: []string{"say"},
|
||||
Short: "Echo anything to the screen",
|
||||
Long: `an utterly useless command for testing.`,
|
||||
Run: func(cmd *Command, args []string) {
|
||||
te = args
|
||||
},
|
||||
@ -38,7 +39,9 @@ var cmdTimes = &Command{
|
||||
Use: "times [# times] [string to echo]",
|
||||
Short: "Echo anything to the screen more times",
|
||||
Long: `an slightly useless command for testing.`,
|
||||
Run: timesRunner,
|
||||
Run: func(cmd *Command, args []string) {
|
||||
tt = args
|
||||
},
|
||||
}
|
||||
|
||||
var cmdRootNoRun = &Command{
|
||||
@ -62,10 +65,6 @@ var cmdRootWithRun = &Command{
|
||||
},
|
||||
}
|
||||
|
||||
func timesRunner(cmd *Command, args []string) {
|
||||
tt = args
|
||||
}
|
||||
|
||||
func flagInit() {
|
||||
cmdEcho.ResetFlags()
|
||||
cmdPrint.ResetFlags()
|
||||
@ -195,8 +194,8 @@ func TestChildCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChildCommandPrefix(t *testing.T) {
|
||||
noRRSetupTest("ech tim one two")
|
||||
func TestCommandAlias(t *testing.T) {
|
||||
noRRSetupTest("say times one two")
|
||||
|
||||
if te != nil || tp != nil {
|
||||
t.Error("Wrong command called")
|
||||
@ -226,23 +225,6 @@ func TestChildSameName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChildSameNamePrefix(t *testing.T) {
|
||||
c := initializeWithSameName()
|
||||
c.AddCommand(cmdPrint, cmdEcho)
|
||||
c.SetArgs(strings.Split("pr one two", " "))
|
||||
c.Execute()
|
||||
|
||||
if te != nil || tt != nil {
|
||||
t.Error("Wrong command called")
|
||||
}
|
||||
if tp == nil {
|
||||
t.Error("Wrong command called")
|
||||
}
|
||||
if strings.Join(tp, " ") != "one two" {
|
||||
t.Error("Command didn't parse correctly")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlagLong(t *testing.T) {
|
||||
noRRSetupTest("echo --intone=13 something here")
|
||||
|
||||
|
Reference in New Issue
Block a user