From 56a101694c72dd524414eac072740f3e112afa64 Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Tue, 6 Sep 2022 09:14:31 +0200 Subject: [PATCH] Drop Do (#36) --- GUIDE.md | 2 +- README.md | 4 ++-- acmd.go | 7 ------- acmd_test.go | 22 ---------------------- 4 files changed, 3 insertions(+), 32 deletions(-) diff --git a/GUIDE.md b/GUIDE.md index b6222e7..eaf47c3 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -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 diff --git a/README.md b/README.md index 7fccf47..929aaf6 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ 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 }, @@ -46,7 +46,7 @@ cmds := []acmd.Command{ { 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 }, diff --git a/acmd.go b/acmd.go index 83703b6..582616b 100644 --- a/acmd.go +++ b/acmd.go @@ -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 @@ -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: diff --git a/acmd_test.go b/acmd_test.go index 00a57e3..a55fd3b 100644 --- a/acmd_test.go +++ b/acmd_test.go @@ -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"