Skip to content

Commit

Permalink
Drop Do (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Sep 6, 2022
1 parent 1b0fa23 commit 56a1016
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 32 deletions.
2 changes: 1 addition & 1 deletion GUIDE.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,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 Down Expand Up @@ -68,9 +64,6 @@ type FlagsGetter interface {
// 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
Original file line number Diff line number Diff line change
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

0 comments on commit 56a1016

Please sign in to comment.