github.com/tcncloud/wollemi@v0.8.1/adapters/cobra/fmt.go (about) 1 package cobra 2 3 import ( 4 "github.com/spf13/cobra" 5 6 "github.com/tcncloud/wollemi/ports/ctl" 7 "github.com/tcncloud/wollemi/ports/wollemi" 8 ) 9 10 func FmtCmd(app ctl.Application) *cobra.Command { 11 config := wollemi.Config{ 12 Gofmt: wollemi.Gofmt{ 13 Rewrite: wollemi.Bool(false), 14 }, 15 } 16 17 cmd := &cobra.Command{ 18 Use: "fmt [path...]", 19 Short: "format build files", 20 Long: Description(` 21 Formats please build files. Formatting modifications include: 22 - Double quoted strings instead of single quoted strings. 23 - Deduplication of attribute list entries. 24 - Ordering of attribute list entries. 25 - Ordering of rule attributes. 26 - Deletion of empty build files. 27 - Consistent build identifiers. 28 - Text alignment. 29 `), 30 Example: Long(` 31 Format a specific build file. 32 $ wollemi fmt project/service/routes 33 34 Recursively format all build files under the routes directory. 35 $ wollemi fmt project/service/routes/... 36 37 Recursively format all build files under the working directory. 38 $ wollemi fmt 39 `), 40 RunE: func(cmd *cobra.Command, args []string) error { 41 wollemi, err := app.Wollemi() 42 if err != nil { 43 return err 44 } 45 46 return wollemi.Format(config, args) 47 }, 48 } 49 50 return cmd 51 }