Skip to content

Commit

Permalink
fix: formatter option missing value
Browse files Browse the repository at this point in the history
  • Loading branch information
haunt98 committed Nov 24, 2022
1 parent 164bd6b commit 90e0bb0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 10 additions & 1 deletion internal/cli/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"fmt"

"github.com/haunt98/gofimports/internal/imports"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -34,7 +35,15 @@ func (a *action) Run(c *cli.Context) error {
return a.RunHelp(c)
}

fmt.Println(c.Args().Slice())
f := imports.NewFormmater(
imports.FormatterWithList(a.flags.list),
imports.FormatterWithWrite(a.flags.write),
imports.FormatterWithDiff(a.flags.diff),
)

if err := f.Format(c.Args().Slice()...); err != nil {
return fmt.Errorf("imports formatter: failed to format %v: %w", c.Args().Slice(), err)
}

return nil
}
12 changes: 6 additions & 6 deletions internal/imports/formatter_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package imports

type FormatterOptionFn func(*Formatter)

func FormatterWithList() FormatterOptionFn {
func FormatterWithList(isList bool) FormatterOptionFn {
return func(f *Formatter) {
f.isList = true
f.isList = isList
}
}

func FormatterWithWrite() FormatterOptionFn {
func FormatterWithWrite(isWrite bool) FormatterOptionFn {
return func(f *Formatter) {
f.isWrite = true
f.isWrite = isWrite
}
}

func FormatterWithDiff() FormatterOptionFn {
func FormatterWithDiff(isDiff bool) FormatterOptionFn {
return func(f *Formatter) {
f.isDiff = true
f.isDiff = isDiff
}
}

0 comments on commit 90e0bb0

Please sign in to comment.