Skip to content

Commit e0b9131

Browse files
authored
Do should work (#35)
1 parent 378a78b commit e0b9131

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

acmd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ type Command struct {
5858
// simple way to get exec function
5959
func (cmd *Command) getExec() func(ctx context.Context, args []string) error {
6060
switch {
61+
case cmd.Do != nil:
62+
cmd.ExecFunc = cmd.Do
63+
fallthrough
6164
case cmd.ExecFunc != nil:
6265
return cmd.ExecFunc
6366
case cmd.Exec != nil:

acmd_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,28 @@ func TestCommand_IsHidden(t *testing.T) {
354354
}
355355
}
356356

357+
func TestDoShouldWork(t *testing.T) {
358+
var ok bool
359+
360+
cmds := []Command{
361+
{
362+
Name: "foo",
363+
Do: func(ctx context.Context, args []string) error {
364+
ok = true
365+
return nil
366+
},
367+
},
368+
}
369+
370+
r := RunnerOf(cmds, Config{
371+
Args: []string{"./someapp", "foo"},
372+
AppName: "myapp",
373+
})
374+
375+
failIfErr(t, r.Run())
376+
mustEqual(t, ok, true)
377+
}
378+
357379
func TestExit(t *testing.T) {
358380
wantStatus := 42
359381
wantOutput := "myapp: code 42\n"

0 commit comments

Comments
 (0)