diff --git a/.hof/shadow/Cli/cmd/hof/cmd/gen.go b/.hof/shadow/Cli/cmd/hof/cmd/gen.go index ae276ef31..936eedd4b 100644 --- a/.hof/shadow/Cli/cmd/hof/cmd/gen.go +++ b/.hof/shadow/Cli/cmd/hof/cmd/gen.go @@ -66,14 +66,15 @@ hof gen data.cue ... func init() { - GenCmd.Flags().BoolVarP(&(flags.GenFlags.Stats), "stats", "s", false, "Print generator statistics") - GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Generator), "generator", "G", nil, "Generators to run, default is all discovered") - GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Template), "template", "T", nil, "Template mappings to render as ';;'") + GenCmd.Flags().BoolVarP(&(flags.GenFlags.Stats), "stats", "s", false, "print generator statistics") + GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Generator), "generator", "G", nil, "generator tags to run, default is all") + GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Template), "template", "T", nil, "template mappings to render as ';;'") GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Partial), "partial", "P", nil, "file globs to partial templates to register with the templates") GenCmd.Flags().BoolVarP(&(flags.GenFlags.Diff3), "diff3", "D", false, "enable diff3 support for adhoc render, generators are configured in code") GenCmd.Flags().BoolVarP(&(flags.GenFlags.Watch), "watch", "w", false, "run in watch mode, regenerating when files change") GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.WatchGlobs), "watch-globs", "W", nil, "filepath globs to watch for changes and regen") GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.WatchXcue), "watch-xcue", "X", nil, "like watch, but skips CUE reload, useful when working on templates, can be used with watch") + GenCmd.Flags().StringVarP(&(flags.GenFlags.CreateModule), "create-module", "", "", "output path to write a generator module for the given flags") } func GenRun(args []string) (err error) { diff --git a/.hof/shadow/Cli/cmd/hof/flags/gen.go b/.hof/shadow/Cli/cmd/hof/flags/gen.go index 14516fea9..75fcff91d 100644 --- a/.hof/shadow/Cli/cmd/hof/flags/gen.go +++ b/.hof/shadow/Cli/cmd/hof/flags/gen.go @@ -1,14 +1,15 @@ package flags type GenFlagpole struct { - Stats bool - Generator []string - Template []string - Partial []string - Diff3 bool - Watch bool - WatchGlobs []string - WatchXcue []string + Stats bool + Generator []string + Template []string + Partial []string + Diff3 bool + Watch bool + WatchGlobs []string + WatchXcue []string + CreateModule string } var GenFlags GenFlagpole diff --git a/cmd/hof/cmd/gen.go b/cmd/hof/cmd/gen.go index f25dd03bb..8e710aa76 100644 --- a/cmd/hof/cmd/gen.go +++ b/cmd/hof/cmd/gen.go @@ -68,14 +68,15 @@ hof gen data.cue ... func init() { - GenCmd.Flags().BoolVarP(&(flags.GenFlags.Stats), "stats", "s", false, "Print generator statistics") - GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Generator), "generator", "G", nil, "Generators to run, default is all discovered") - GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Template), "template", "T", nil, "Template mappings to render as ';;'") + GenCmd.Flags().BoolVarP(&(flags.GenFlags.Stats), "stats", "s", false, "print generator statistics") + GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Generator), "generator", "G", nil, "generator tags to run, default is all") + GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Template), "template", "T", nil, "template mappings to render as ';;'") GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.Partial), "partial", "P", nil, "file globs to partial templates to register with the templates") GenCmd.Flags().BoolVarP(&(flags.GenFlags.Diff3), "diff3", "D", false, "enable diff3 support for adhoc render, generators are configured in code") GenCmd.Flags().BoolVarP(&(flags.GenFlags.Watch), "watch", "w", false, "run in watch mode, regenerating when files change") GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.WatchGlobs), "watch-globs", "W", nil, "filepath globs to watch for changes and regen") GenCmd.Flags().StringSliceVarP(&(flags.GenFlags.WatchXcue), "watch-xcue", "X", nil, "like watch, but skips CUE reload, useful when working on templates, can be used with watch") + GenCmd.Flags().StringVarP(&(flags.GenFlags.CreateModule), "create-module", "", "", "output path to write a generator module for the given flags") } func GenRun(args []string) (err error) { diff --git a/cmd/hof/flags/gen.go b/cmd/hof/flags/gen.go index 9b18358d8..f1346cad6 100644 --- a/cmd/hof/flags/gen.go +++ b/cmd/hof/flags/gen.go @@ -1,14 +1,15 @@ package flags type GenFlagpole struct { - Stats bool - Generator []string - Template []string - Partial []string - Diff3 bool - Watch bool - WatchGlobs []string - WatchXcue []string + Stats bool + Generator []string + Template []string + Partial []string + Diff3 bool + Watch bool + WatchGlobs []string + WatchXcue []string + CreateModule string } var GenFlags GenFlagpole \ No newline at end of file diff --git a/design/cli/cmds/gen.cue b/design/cli/cmds/gen.cue index fecf26231..d437b0643 100644 --- a/design/cli/cmds/gen.cue +++ b/design/cli/cmds/gen.cue @@ -17,7 +17,7 @@ import ( Name: "stats" Type: "bool" Default: "false" - Help: "Print generator statistics" + Help: "print generator statistics" Long: "stats" Short: "s" }, @@ -25,7 +25,7 @@ import ( Name: "generator" Type: "[]string" Default: "nil" - Help: "Generators to run, default is all discovered" + Help: "generator tags to run, default is all" Long: "generator" Short: "G" }, @@ -33,7 +33,7 @@ import ( Name: "template" Type: "[]string" Default: "nil" - Help: "Template mappings to render as ';;'" + Help: "template mappings to render as ';;'" Long: "template" Short: "T" }, @@ -77,6 +77,13 @@ import ( Long: "watch-xcue" Short: "X" }, + { + Name: "CreateModule" + Type: "string" + Default: "" + Help: "output path to write a generator module for the given flags" + Long: "create-module" + }, ] } diff --git a/test/watch/data.cue b/test/watch/data.cue index 6b32a81fc..edc44b0bb 100644 --- a/test/watch/data.cue +++ b/test/watch/data.cue @@ -2,6 +2,7 @@ import "strings" users: [n=string]: { name: n, NAME: strings.ToUpper(n) } users: { + aaah: role: "cat" alice: role: "user" bob: role: "user" cow: role: "mooer" diff --git a/test/watch/ext.txt b/test/watch/ext.txt new file mode 100644 index 000000000..f67696052 --- /dev/null +++ b/test/watch/ext.txt @@ -0,0 +1,9 @@ +package foo +{{ range .users }} +// function {{ camelT .name }} pretend time +func {{ camelT .name }}( {{ title .role }} int ) error { + fmt.Println("hey {{ .NAME }}!!") + + return nil +} +{{ end }} diff --git a/test/watch/out.txt b/test/watch/out.txt index db8d6e3ce..010ba88bb 100644 --- a/test/watch/out.txt +++ b/test/watch/out.txt @@ -1,3 +1,10 @@ +// hallo!!! +NAME: AAAH +name: aaah +role: cat + + + // hallo!!! NAME: ALICE name: alice diff --git a/test/watch/template.txt b/test/watch/template.txt deleted file mode 100644 index 7ffc35a4d..000000000 --- a/test/watch/template.txt +++ /dev/null @@ -1,9 +0,0 @@ -package foo -{{ range .users }} -// function {{ camelT .name }} yells loudly -func {{ camelT .name }}( {{ .role }} string ) error { - fmt.Println("hey {{ .NAME }}!!") - - return nil -} -{{ end }} diff --git a/test/watch/users.txt b/test/watch/users.txt new file mode 100644 index 000000000..63be2ffbd --- /dev/null +++ b/test/watch/users.txt @@ -0,0 +1,46 @@ +package foo + +// function Aaah pretend time +func Aaah( Cat int ) error { + fmt.Println("hey AAAH!!") + + return nil +} + +// function Alice pretend time +func Alice( User int ) error { + fmt.Println("hey ALICE!!") + + // if in wonderland? + // if white rabbit? + + return nil +} + +// function Bob pretend time +func Bob( User int ) error { + fmt.Println("hey BOB!!") + + return nil +} + +// function Cow pretend time +func Cow( Mooer int ) error { + fmt.Println("hey COW!!") + + return nil +} + +// function Darth pretend time +func Darth( Evil int ) error { + fmt.Println("hey DARTH!!") + + return nil +} + +// function Mary pretend time +func Mary( Admin int ) error { + fmt.Println("hey MARY!!") + + return nil +} \ No newline at end of file