Skip to content

Commit

Permalink
wordsmith flags, multiwatch files, add --create-module flag
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed Jul 9, 2022
1 parent 10e7b6b commit cf9ab7e
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 34 deletions.
7 changes: 4 additions & 3 deletions .hof/shadow/Cli/cmd/hof/cmd/gen.go
Expand Up @@ -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 '<filepath>;<?cuepath>;<?outpath>'")
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 '<filepath>;<?cuepath>;<?outpath>'")
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) {
Expand Down
17 changes: 9 additions & 8 deletions .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
7 changes: 4 additions & 3 deletions cmd/hof/cmd/gen.go
Expand Up @@ -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 '<filepath>;<?cuepath>;<?outpath>'")
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 '<filepath>;<?cuepath>;<?outpath>'")
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) {
Expand Down
17 changes: 9 additions & 8 deletions 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
13 changes: 10 additions & 3 deletions design/cli/cmds/gen.cue
Expand Up @@ -17,23 +17,23 @@ import (
Name: "stats"
Type: "bool"
Default: "false"
Help: "Print generator statistics"
Help: "print generator statistics"
Long: "stats"
Short: "s"
},
{
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"
},
{
Name: "template"
Type: "[]string"
Default: "nil"
Help: "Template mappings to render as '<filepath>;<?cuepath>;<?outpath>'"
Help: "template mappings to render as '<filepath>;<?cuepath>;<?outpath>'"
Long: "template"
Short: "T"
},
Expand Down Expand Up @@ -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"
},
]
}

Expand Down
1 change: 1 addition & 0 deletions test/watch/data.cue
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions 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 }}
7 changes: 7 additions & 0 deletions test/watch/out.txt
@@ -1,3 +1,10 @@
// hallo!!!
NAME: AAAH
name: aaah
role: cat



// hallo!!!
NAME: ALICE
name: alice
Expand Down
9 changes: 0 additions & 9 deletions test/watch/template.txt

This file was deleted.

46 changes: 46 additions & 0 deletions 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
}

0 comments on commit cf9ab7e

Please sign in to comment.