feature: add DefaultCommand field to App

See issue #1307 for context.
This commit is contained in:
James Alavosus
2022-05-05 23:50:22 -04:00
parent f1fc873f1f
commit 32dec1ddaa
2 changed files with 98 additions and 3 deletions

View File

@@ -469,6 +469,42 @@ func TestApp_Command(t *testing.T) {
}
}
var defaultCommandAppTests = []struct {
cmdName string
defaultCmd string
expected bool
}{
{"foobar", "foobar", true},
{"batbaz", "foobar", true},
{"b", "", true},
{"f", "", true},
{"", "foobar", true},
{"", "", true},
{" ", "", false},
{"bat", "batbaz", false},
{"nothing", "batbaz", false},
{"nothing", "", false},
}
func TestApp_RunDefaultCommand(t *testing.T) {
for _, test := range defaultCommandAppTests {
testTitle := fmt.Sprintf("command=%[1]s-default=%[2]s", test.cmdName, test.defaultCmd)
t.Run(testTitle, func(t *testing.T) {
app := &App{
DefaultCommand: test.defaultCmd,
Commands: []*Command{
{Name: "foobar", Aliases: []string{"f"}},
{Name: "batbaz", Aliases: []string{"b"}},
},
}
err := app.Run([]string{"c", test.cmdName})
expect(t, err == nil, test.expected)
})
}
}
func TestApp_Setup_defaultsReader(t *testing.T) {
app := &App{}
app.Setup()