Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do should work #35

Merged
merged 1 commit into from Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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