github.com/gobuffalo/buffalo-cli/v2@v2.0.0-alpha.15.0.20200919213536-a7350c8e6799/cli/cmds/fix/main.go (about) 1 package fix 2 3 import ( 4 "context" 5 6 "github.com/gobuffalo/plugins" 7 "github.com/gobuffalo/plugins/plugio" 8 "github.com/gobuffalo/plugins/plugprint" 9 ) 10 11 func (fc *Cmd) Main(ctx context.Context, root string, args []string) error { 12 plugs := fc.ScopedPlugins() 13 14 if p := FindFixerFromArgs(args, plugs); p != nil { 15 return p.Fix(ctx, root, args[1:]) 16 } 17 18 flags := fc.Flags() 19 20 if err := flags.Parse(args); err != nil { 21 return plugins.Wrap(fc, err) 22 } 23 24 if fc.help { 25 return plugprint.Print(plugio.Stdout(fc.ScopedPlugins()...), fc) 26 } 27 28 return fc.run(ctx, root, args) 29 } 30 31 // Fix runs any Fixers that are in the Plugins. 32 // If no arguments are provided it will run all fixers in the Plugins. 33 // Otherwise Fix will run the fixers for the arguments provided. 34 // buffalo fix 35 // buffalo fix plush pop 36 // buffalo fix -h 37 func (fc *Cmd) run(ctx context.Context, root string, args []string) error { 38 plugs := fc.ScopedPlugins() 39 40 for _, p := range plugs { 41 f, ok := p.(Fixer) 42 if !ok { 43 continue 44 } 45 46 if err := f.Fix(ctx, root, []string{}); err != nil { 47 return plugins.Wrap(f, err) 48 } 49 } 50 51 return nil 52 }