Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed Apr 7, 2024
1 parent edb9d46 commit a3e575b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
6 changes: 1 addition & 5 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/cli/cmd_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 1 addition & 4 deletions internal/cli/common_flags.go
Original file line number Diff line number Diff line change
@@ -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{
Expand Down Expand Up @@ -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",
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
22 changes: 12 additions & 10 deletions internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
// }

0 comments on commit a3e575b

Please sign in to comment.