Skip to content

Commit

Permalink
hof/gen: implement --as-generator, other cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed Jul 10, 2022
1 parent 5c02248 commit 94a5986
Show file tree
Hide file tree
Showing 18 changed files with 513 additions and 78 deletions.
6 changes: 5 additions & 1 deletion .hof/shadow/Cli/cmd/hof/cmd/gen.go
Expand Up @@ -57,6 +57,10 @@ hof gen data.cue ...
# Check the tests for complete examples
https://github.com/hofstadter-io/hof/tree/_dev/test/render
# Turn any hof gen flags into a reusable generator module
hof gen [entrypoints] flags... --as-module [name]
hof gen [entrypoints] -G [name]
# Compose code gen mappings into reusable modules with
hof gen app.cue -G frontend -G backend -G migrations
https://docs.hofstadter.io/first-example/
Expand All @@ -75,7 +79,7 @@ func init() {
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")
GenCmd.Flags().StringVarP(&(flags.GenFlags.AsModule), "as-module", "", "", "<name> in the printed output, for the given flags as a generator module")
}

func GenRun(args []string) (err error) {
Expand Down
20 changes: 10 additions & 10 deletions .hof/shadow/Cli/cmd/hof/flags/gen.go
@@ -1,16 +1,16 @@
package flags

type GenFlagpole struct {
List bool
Stats bool
Generator []string
Template []string
Partial []string
Diff3 bool
Watch bool
WatchGlobs []string
WatchXcue []string
CreateModule string
List bool
Stats bool
Generator []string
Template []string
Partial []string
Diff3 bool
Watch bool
WatchGlobs []string
WatchXcue []string
AsModule string
}

var GenFlags GenFlagpole
6 changes: 5 additions & 1 deletion cmd/hof/cmd/gen.go
Expand Up @@ -59,6 +59,10 @@ hof gen data.cue ...
# Check the tests for complete examples
https://github.com/hofstadter-io/hof/tree/_dev/test/render
# Turn any hof gen flags into a reusable generator module
hof gen [entrypoints] flags... --as-module [name]
hof gen [entrypoints] -G [name]
# Compose code gen mappings into reusable modules with
hof gen app.cue -G frontend -G backend -G migrations
https://docs.hofstadter.io/first-example/
Expand All @@ -77,7 +81,7 @@ func init() {
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")
GenCmd.Flags().StringVarP(&(flags.GenFlags.AsModule), "as-module", "", "", "<name> in the printed output, for the given flags as a generator module")
}

func GenRun(args []string) (err error) {
Expand Down
20 changes: 10 additions & 10 deletions cmd/hof/flags/gen.go
@@ -1,16 +1,16 @@
package flags

type GenFlagpole struct {
List bool
Stats bool
Generator []string
Template []string
Partial []string
Diff3 bool
Watch bool
WatchGlobs []string
WatchXcue []string
CreateModule string
List bool
Stats bool
Generator []string
Template []string
Partial []string
Diff3 bool
Watch bool
WatchGlobs []string
WatchXcue []string
AsModule string
}

var GenFlags GenFlagpole
10 changes: 7 additions & 3 deletions design/cli/cmds/gen.cue
Expand Up @@ -86,11 +86,11 @@ import (
Short: "X"
},
{
Name: "CreateModule"
Name: "AsModule"
Type: "string"
Default: ""
Help: "output path to write a generator module for the given flags"
Long: "create-module"
Help: "<name> in the printed output, for the given flags as a generator module"
Long: "as-module"
},
]
}
Expand Down Expand Up @@ -144,6 +144,10 @@ hof gen data.cue ...
# Check the tests for complete examples
https://github.com/hofstadter-io/hof/tree/_dev/test/render
# Turn any hof gen flags into a reusable generator module
hof gen [entrypoints] flags... --as-module [name]
hof gen [entrypoints] -G [name]
# Compose code gen mappings into reusable modules with
hof gen app.cue -G frontend -G backend -G migrations
https://docs.hofstadter.io/first-example/
Expand Down
16 changes: 8 additions & 8 deletions hof.cue
Expand Up @@ -8,46 +8,46 @@ import (
d_cfg "github.com/hofstadter-io/hof/design/config"
)

Cli: _ @gen(cli,hof)
Cli: g_cli.#HofGenerator & {
@gen(cli,hof)
Outdir: "./"
Cli: d_cli.#CLI
WatchGlobs: ["./design/**/*"]
WatchXcue: ["./cue.mod/**/*"]
WatchXcue: ["./cue.mod/**/*"]
}

Context: _ @gen(cuefig,context,ctx)
Context: g_cuefig.#HofGenerator & {
@gen(cuefig,context,ctx)
Outdir: "gen/"
Config: d_cfg.#HofContext
}

Config: _ @gen(cuefig,config,cfg)
Config: g_cuefig.#HofGenerator & {
@gen(cuefig,config,cfg)
Outdir: "gen/"
Config: d_cfg.#HofConfig
}

Secret: _ @gen(cuefig,secret,shh,ssh)
Secret: g_cuefig.#HofGenerator & {
@gen(cuefig,secret,shh,ssh)
Outdir: "gen/"
Config: d_cfg.#HofSecret
}

UserContext: _ @gen(cuefig,ucontext,uctx)
UserContext: g_cuefig.#HofGenerator & {
@gen(cuefig,ucontext,uctx)
Outdir: "gen/"
Config: d_cfg.#HofUserContext
}

UserConfig: _ @gen(cuefig,uconfig,ucfg)
UserConfig: g_cuefig.#HofGenerator & {
@gen(cuefig,uconfig,ucfg)
Outdir: "gen/"
Config: d_cfg.#HofUserConfig
}

UserSecret: _ @gen(cuefig,usecret,ushh,ussh)
UserSecret: g_cuefig.#HofGenerator & {
@gen(cuefig,usecret,ushh,ussh)
Outdir: "gen/"
Config: d_cfg.#HofUserSecret
}

0 comments on commit 94a5986

Please sign in to comment.