fix: formatter option missing value
parent
164bd6b6e8
commit
90e0bb0a6b
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue