diff --git a/acmd.go b/acmd.go index 9a0fbd5..2eff864 100644 --- a/acmd.go +++ b/acmd.go @@ -58,6 +58,9 @@ type Command struct { // simple way to get exec function func (cmd *Command) getExec() func(ctx context.Context, args []string) error { switch { + case cmd.Do != nil: + cmd.ExecFunc = cmd.Do + fallthrough case cmd.ExecFunc != nil: return cmd.ExecFunc case cmd.Exec != nil: diff --git a/acmd_test.go b/acmd_test.go index a55fd3b..00a57e3 100644 --- a/acmd_test.go +++ b/acmd_test.go @@ -354,6 +354,28 @@ func TestCommand_IsHidden(t *testing.T) { } } +func TestDoShouldWork(t *testing.T) { + var ok bool + + cmds := []Command{ + { + Name: "foo", + Do: func(ctx context.Context, args []string) error { + ok = true + return nil + }, + }, + } + + r := RunnerOf(cmds, Config{ + Args: []string{"./someapp", "foo"}, + AppName: "myapp", + }) + + failIfErr(t, r.Run()) + mustEqual(t, ok, true) +} + func TestExit(t *testing.T) { wantStatus := 42 wantOutput := "myapp: code 42\n"