github.com/machinebox/remoto@v0.1.2-0.20191024144331-eff21a7d321f/templates/x/go/cli/cobra-cli.go.plush (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/spf13/cobra" 8 ) 9 10 func main() { 11 12 <%= for (service) in def.Services { %><%= for (method) in service.Methods { %><%= camelize_down(service.Name) %>Cmd.AddCommand(<%= camelize_down(service.Name) %><%= method.Name %>Cmd) 13 <% } %>rootCmd.AddCommand(<%= camelize_down(service.Name) %>Cmd) 14 15 <% } %> 16 if err := rootCmd.Execute(); err != nil { 17 fmt.Fprintf(os.Stderr, "%v\n", err) 18 os.Exit(1) 19 } 20 } 21 22 var rootCmd = &cobra.Command{ 23 Use: "<%= def.PackageName %> service method [data]", 24 Short: "<%= def.PackageComment %>", 25 Long: `<%= def.PackageComment %>`, 26 Run: func(cmd *cobra.Command, args []string) { 27 28 }, 29 Args: cobra.MinimumNArgs(2), 30 } 31 32 <%= for (service) in def.Services { %> 33 // <%= camelize_down(service.Name) %>Cmd is the service command for 34 // information. 35 var <%= camelize_down(service.Name) %>Cmd = &cobra.Command{ 36 Use: "<%= def.PackageName %> <%= service.Name %> method [data]", 37 Short: "<%= service.Comment %>", 38 Long: `<%= service.Comment %>`, 39 Run: func(cmd *cobra.Command, args []string) { 40 41 }, 42 } 43 44 <%= for (method) in service.Methods { %> 45 // <%= camelize_down(service.Name) %><%= method.Name %>Cmd is the method. 46 var <%= camelize_down(service.Name) %><%= method.Name %>Cmd = &cobra.Command{ 47 Use: "<%= def.PackageName %> <%= service.Name %> <%= method.Name %> [data]", 48 Short: "<%= method.Comment %>", 49 Long: `<%= method.Comment %>`, 50 Run: func(cmd *cobra.Command, args []string) { 51 52 }, 53 } 54 <% } %> 55 <% } %>