Skip to content

Commit

Permalink
Do should work (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Aug 23, 2022
1 parent 378a78b commit e0b9131
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions acmd.go
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions acmd_test.go
Expand Up @@ -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"
Expand Down

0 comments on commit e0b9131

Please sign in to comment.