Skip to content

Commit

Permalink
minor edits to getting-started/code-generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Worm committed May 27, 2024
1 parent 8386a99 commit 32a8155
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
12 changes: 8 additions & 4 deletions docs/code/getting-started/code-generation/adhoc-mod-snippet.cue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ foo: gen.#Generator: {
// input data
In: _

Out: [
// list of files to generate
]
// normally when writing generators as code
// you add the CUE to turn In -> Out
// - provide project specific config and flags
// - dynamically decide what files to generate

// other fields filled by hof
// list of files to generate
Out: [...]

// other fields filled by hof when you turn adhoc -> reusable
}
20 changes: 13 additions & 7 deletions docs/content/getting-started/code-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,27 @@ You can find more examples in the
## What are Generators and Modules


Generators are configurations for the `hof gen` flag, typically defined
in CUE modules or Git repositories.
Hof Generators are CUE code that define a `hof gen` command,
defined in CUE modules and shared with Git repositories.

To turn your ad-hoc `hof gen ... -T ...` commands into a generator,
add `--as-module <module name>` to the end of your current flag.
Turn any ad-hoc `hof gen ... -T ...` args and flags into a generator by
adding `--as-module <module name>` to the end.
This will generate the equivalent CUE code version for the command.
You can now run `hof gen


{{<codeInner title="> terminal">}}
{{<codeInner title="> terminal" lang="shell">}}
# turn command into foo module
$ hof gen ... --as-module github.com/username/foo

# run generator without remembering flags
$ hof gen [-G <name>]
{{</codeInner>}}

Several files are generated, including a CUE file that houses your generator and additional files for configuring a CUE module.

{{<codePane file="code/getting-started/code-generation/adhoc-mod-snippet.html" title="generator.cue snippet">}}

The next page will provide an overview of modules in general,
and the [first-example](/first-example/) offers detailed instructions for creating a generator from scratch.
The next page will cover modules in general
and the [first-example](/first-example/) is a walkthrough on creating a full-stack application generator from scratch.

0 comments on commit 32a8155

Please sign in to comment.