summaryrefslogtreecommitdiff
path: root/cmd/ponzu/generate.go
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-05-22 21:04:27 -0700
committerGitHub <noreply@github.com>2017-05-22 21:04:27 -0700
commit0b7f607b347e46c823774dabf4969758470ae6fd (patch)
tree9e5d292acba06e4d4b4e4e3009c7a6b7796f6035 /cmd/ponzu/generate.go
parent66c3ad778ccf54566086d535a6ebe4805bf4241f (diff)
parent7276d308986bfcbd2bbe3d22e2887b622fab52e7 (diff)
Merge pull request #148 from ponzu-cms/ponzu-dev
[cli] use spf13/cobra for command line interface
Diffstat (limited to 'cmd/ponzu/generate.go')
-rw-r--r--cmd/ponzu/generate.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/cmd/ponzu/generate.go b/cmd/ponzu/generate.go
index 5211df8..bc94913 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,40 @@ func generateContentType(args []string) error {
return nil
}
+
+var generateCmd = &cobra.Command{
+ Use: "generate <generator type (,...fields)>",
+ Aliases: []string{"gen", "g"},
+ Short: "generate boilerplate code for various Ponzu components",
+ Long: `Generate boilerplate code for various Ponzu components, such as 'content'.
+
+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.`,
+ Example: `$ ponzu gen content review title:"string" body:"string" rating:"int" tags:"[]string"`,
+}
+
+var contentCmd = &cobra.Command{
+ Use: "content <namespace> <field> <field>...",
+ Aliases: []string{"c"},
+ Short: "generates a new content type",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return generateContentType(args)
+ },
+}
+
+func init() {
+ generateCmd.AddCommand(contentCmd)
+ RegisterCmdlineCommand(generateCmd)
+}