diff --git a/internal/cli/action.go b/internal/cli/action.go index 4ba959d..b73b965 100644 --- a/internal/cli/action.go +++ b/internal/cli/action.go @@ -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 } diff --git a/internal/imports/formatter_option.go b/internal/imports/formatter_option.go index 260c681..baec46c 100644 --- a/internal/imports/formatter_option.go +++ b/internal/imports/formatter_option.go @@ -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 } }