diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 68fb17716..93691e1ec 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -26,11 +26,7 @@ func Main() { os.Exit(1) } }() - select { - case <-ctx.Done(): - stop() - } - // TODO(mf): should we os exit or return a code and let the caller decide? + <-ctx.Done() os.Exit(0) } diff --git a/internal/cli/cmd_status.go b/internal/cli/cmd_status.go index 0c7350d80..9a82c47b1 100644 --- a/internal/cli/cmd_status.go +++ b/internal/cli/cmd_status.go @@ -29,10 +29,10 @@ func newStatusCommand(state *state) *ff.Command { state: state, fs: ff.NewFlagSet("status"), } - c.fs.AddFlag(newDirFlag(&c.dir)) - c.fs.AddFlag(newDBStringFlag(&c.dbstring)) - c.fs.AddFlag(newJSONFlag(&c.useJSON)) - c.fs.AddFlag(newTablenameFlag(&c.tablename)) + c.fs.BoolConfig(newJSONFlag(&c.useJSON)) + c.fs.StringConfig(newDirFlag(&c.dir), "") + c.fs.StringConfig(newDBStringFlag(&c.dbstring), "") + c.fs.StringConfig(newTablenameFlag(&c.tablename), goose.DefaultTablename) return &ff.Command{ Name: "status", diff --git a/internal/cli/common_flags.go b/internal/cli/common_flags.go index 41a54174a..57c1e77d1 100644 --- a/internal/cli/common_flags.go +++ b/internal/cli/common_flags.go @@ -1,11 +1,8 @@ package cli import ( - "fmt" - "github.com/peterbourgon/ff/v4" "github.com/peterbourgon/ff/v4/ffval" - "github.com/pressly/goose/v3" ) var requiredFlags = map[string]bool{ @@ -44,7 +41,7 @@ func newJSONFlag(b *bool) ff.FlagConfig { func newTablenameFlag(b *string) ff.FlagConfig { return ff.FlagConfig{ LongName: "table", - Usage: fmt.Sprintf("migration table name (default: %s)", goose.DefaultTablename), + Usage: "migration table name", Value: ffval.NewValue(b), Placeholder: "string", } diff --git a/internal/cli/help.go b/internal/cli/help.go index c315d5307..3c857c0cf 100644 --- a/internal/cli/help.go +++ b/internal/cli/help.go @@ -120,7 +120,7 @@ func rootHelp(cmd *ff.Command, render func(s string) string) ffhelp.Help { buf := bytes.NewBuffer(nil) tw := tabwriter.NewWriter(buf, 0, 0, 2, ' ', 0) for _, v := range keys { - tw.Write([]byte(ffhelp.DefaultLinePrefix + v.name + "\t" + v.description + "\n")) + _, _ = tw.Write([]byte(ffhelp.DefaultLinePrefix + v.name + "\t" + v.description + "\n")) } tw.Flush() section.Lines = append(section.Lines, buf.String()) diff --git a/internal/cli/run.go b/internal/cli/run.go index dffc791c9..ef97a59d5 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -39,7 +39,7 @@ func checkRequiredFlags(cmd *ff.Command) error { cmd = cmd.GetSelected() } var required []string - cmd.Flags.WalkFlags(func(f ff.Flag) error { + if err := cmd.Flags.WalkFlags(func(f ff.Flag) error { name, ok := f.GetLongName() if !ok { return fmt.Errorf("flag %v doesn't have a long name", f) @@ -48,18 +48,20 @@ func checkRequiredFlags(cmd *ff.Command) error { required = append(required, "--"+name) } return nil - }) + }); err != nil { + return err + } if len(required) > 0 { return fmt.Errorf("required flags not set: %v", strings.Join(required, ", ")) } return nil } -func coalesce[T comparable](values ...T) (zero T) { - for _, v := range values { - if v != zero { - return v - } - } - return zero -} +// func coalesce[T comparable](values ...T) (zero T) { +// for _, v := range values { +// if v != zero { +// return v +// } +// } +// return zero +// }