github.com/Accefy/pop@v0.0.0-20230428174248-e9f677eab5b9/soda/cmd/fix.go (about) 1 package cmd 2 3 import ( 4 "os" 5 "path/filepath" 6 "strings" 7 8 "github.com/gobuffalo/pop/v6/fix" 9 "github.com/spf13/cobra" 10 ) 11 12 var fixCmd = &cobra.Command{ 13 Use: "fix", 14 Aliases: []string{"f", "update"}, 15 Short: "Brings pop, soda, and fizz files in line with the latest APIs", 16 RunE: func(cmd *cobra.Command, args []string) error { 17 return filepath.Walk(migrationPath, func(path string, info os.FileInfo, _ error) error { 18 if info == nil { 19 return nil 20 } 21 return fixFizz(path) 22 }) 23 }, 24 } 25 26 func fixFizz(path string) error { 27 ext := strings.ToLower(filepath.Ext(path)) 28 if ext != ".fizz" { 29 return nil 30 } 31 f, err := os.Open(path) 32 if err != nil { 33 return err 34 } 35 defer f.Close() 36 return fix.Fizz(f, f) 37 } 38 39 func init() { 40 RootCmd.AddCommand(fixCmd) 41 }