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

Drop Do #36

Merged
merged 2 commits into from Sep 6, 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
2 changes: 1 addition & 1 deletion GUIDE.md
Expand Up @@ -31,7 +31,7 @@ func run() error {
// Command "server"
Name: "server",
Description: "run mock server",
Do: func(ctx context.Context, args []string) error {
ExecFunc: func(ctx context.Context, args []string) error {
cfg := config.NewConfig()

// Argument ./openapi.yml
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -38,15 +38,15 @@ cmds := []acmd.Command{
{
Name: "now",
Description: "prints current time",
Do: func(ctx context.Context, args []string) error {
ExecFunc: func(ctx context.Context, args []string) error {
fmt.Printf("now: %s\n", now.Format("15:04:05"))
return nil
},
},
{
Name: "status",
Description: "prints status of the system",
Do: func(ctx context.Context, args []string) error {
ExecFunc: func(ctx context.Context, args []string) error {
// do something with ctx :)
return nil
},
Expand Down
7 changes: 0 additions & 7 deletions acmd.go
Expand Up @@ -36,10 +36,6 @@ type Command struct {
// Description of the command.
Description string

// Do will be invoked.
// Deprecated: use ExecFunc or Exec.
Do func(ctx context.Context, args []string) error

// ExecFunc represents the command function.
// Use Exec if you have struct implementing this function.
ExecFunc func(ctx context.Context, args []string) error
Expand All @@ -58,9 +54,6 @@ 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: 0 additions & 22 deletions acmd_test.go
Expand Up @@ -354,28 +354,6 @@ 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