diff options
author | Martin Treusch von Buttlar <martin.tvb@vitraum.de> | 2017-05-15 22:39:14 +0200 |
---|---|---|
committer | Martin Treusch von Buttlar <martin.tvb@vitraum.de> | 2017-05-15 22:39:14 +0200 |
commit | 4c54cc43537fd15cc459030cb792f8171bcd0fd7 (patch) | |
tree | 9e81500281ea4a33685bbf77f7c5ad2bbb3636e2 /cmd/ponzu/generate.go | |
parent | 0cf8aa550a3da63cb1509678bf5add0d73925546 (diff) |
add cobra commands
Diffstat (limited to 'cmd/ponzu/generate.go')
-rw-r--r-- | cmd/ponzu/generate.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cmd/ponzu/generate.go b/cmd/ponzu/generate.go index 5211df8..cc2b93a 100644 --- a/cmd/ponzu/generate.go +++ b/cmd/ponzu/generate.go @@ -8,6 +8,8 @@ import ( "path/filepath" "strings" "text/template" + + "github.com/spf13/cobra" ) type generateType struct { @@ -413,3 +415,39 @@ func generateContentType(args []string) error { return nil } + +var generateCmd = &cobra.Command{ + Use: "generate <generator type (,...fields)>", + Short: "generate boilerplate code for various Ponzu components", + Long: `Generate boilerplate code for various Ponzu components, such as 'content'. + +Example: +$ ponzu gen content review title:"string" body:"string" rating:"int" tags:"[]string" + +The command above will generate a file 'content/review.go' with boilerplate +methods, as well as struct definition, and corresponding field tags like: + +type Review struct { + Title string ` + "`json:" + `"title"` + "`" + ` + Body string ` + "`json:" + `"body"` + "`" + ` + Rating int ` + "`json:" + `"rating"` + "`" + ` + Tags []string ` + "`json:" + `"tags"` + "`" + ` +} + +The generate command will intelligently parse more sophisticated field names +such as 'field_name' and convert it to 'FieldName' and vice versa, only where +appropriate as per common Go idioms. Errors will be reported, but successful +generate commands return nothing.`, +} + +var contentCmd = &cobra.Command{ + Use: "content <namespace> <field> <field>...", + RunE: func(cmd *cobra.Command, args []string) error { + return generateContentType(args) + }, +} + +func init() { + generateCmd.AddCommand(contentCmd) + rootCmd.AddCommand(generateCmd) +} |