fix: formatter option missing value

main
sudo pacman -Syu 2022-11-25 00:21:59 +07:00
parent 164bd6b6e8
commit 90e0bb0a6b
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
2 changed files with 16 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package cli
import (
"fmt"
"github.com/haunt98/gofimports/internal/imports"
"github.com/urfave/cli/v2"
)
@ -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
}

View File

@ -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
}
}