Skip to content

Commit

Permalink
hof/gen: rename PackageName to ModuleName in Go code
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed Aug 16, 2023
1 parent eabf15b commit c661ae1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
4 changes: 4 additions & 0 deletions ci/hof/packer/dagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ func main() {
t = WithGcloudRemoteBash(t, vmName, "echo '{}' | hof gen - -T :=foo.json")

// todo, what do we want to run on the remote VM?
// we test everthing with docker, we added these tests as a sanity on the tools
// what we really need is the "full" test suite with none (no container runtime)
// "full" because there are some tests we cannot run, because you need a container formatter
// what is not easy is to separate the directory of testscripts, unless we make 2 dirs, which might be the easy solution
if runtime != "none" {
t = WithGcloudRemoteBash(t, vmName, "hof fmt pull [email protected]")
t = WithGcloudRemoteBash(t, vmName, "hof fmt start [email protected]")
Expand Down
2 changes: 1 addition & 1 deletion docs/content/code-generation/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ We have used this for
- Building higher level generators, for example an APP which has Client, Server, and Database subgenerators with a single input.


##### PackageName
##### ModuleName

This is the CUE module name of your generator.
It is used for indexing into the `cue.mod` folder
Expand Down
2 changes: 1 addition & 1 deletion lib/gen/cmd/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func EnrichGeneratorBuilder(R *Runtime) func (R *runtime.Runtime, G *gen.Generat
See GitHub issue: https://github.com/hofstadter-io/hof/issues/103
`

if G.PackageName == "" {
if G.ModuleName == "" {
if R.Flags.Verbosity > 0 {
fmt.Printf(warnModuleAuthorFmtStr, G.Hof.Metadata.Name, G.Hof.Path)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/gen/cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (R *Runtime) buildWatchLists() (wfiles, xfiles []string, err error) {
}

// when package is set or not...
if G.PackageName == "" {
if G.ModuleName == "" {
// when not set, we are probably in the module
// thus we are in all-in-one mode or module authoring

Expand Down
10 changes: 5 additions & 5 deletions lib/gen/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (G *Generator) DecodeFromCUE(root cue.Value) (errs []error) {
errs = append(errs, serr...)
}

if err := G.decodePackageName(); err != nil {
if err := G.decodeModuleName(); err != nil {
errs = append(errs, err)
}

Expand Down Expand Up @@ -155,7 +155,7 @@ func (G *Generator) PrintInfo() {
fmt.Println("EPrtl: ", len(G.EmbeddedPartials))
fmt.Println("EStcs: ", len(G.EmbeddedStatics))
fmt.Println()
fmt.Println(G.PackageName, G.Disabled)
fmt.Println(G.ModuleName, G.Disabled)
fmt.Println("Diff3: ", G.UseDiff3)
fmt.Println("TMap: ", len(G.TemplateMap))
fmt.Println("PMap: ", len(G.PartialsMap))
Expand Down Expand Up @@ -477,18 +477,18 @@ func (G *Generator) decodeFile(file *File, val cue.Value) error {
return nil
}

func (G *Generator) decodePackageName() error {
func (G *Generator) decodeModuleName() error {
val := G.CueValue.LookupPath(cue.ParsePath("ModuleName"))
if val.Err() != nil {
pval := G.CueValue.LookupPath(cue.ParsePath("PackageName"))
pval := G.CueValue.LookupPath(cue.ParsePath("ModuleName"))
if pval.Err() != nil {
return fmt.Errorf("while decoding ModuleName: %w %w", val.Err(), pval.Err())
}
fmt.Println("warning, PackageName is being deprecated, use ModuleName going forward")
val = pval
}

return val.Decode(&G.PackageName)
return val.Decode(&G.ModuleName)
}

func (G *Generator) decodeSubgens(root cue.Value) (errs []error) {
Expand Down
23 changes: 12 additions & 11 deletions lib/gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ type Generator struct {
parent *Generator

// Used for indexing into the vendor directory...
// TODO, rename this ModuleName
PackageName string
// This should be `ModuleName: string | *"github.com/..." in your generator
// and set to "" if you use the generator from within the module itself
ModuleName string

// Use Diff3 & Shadow
Diff3FlagSet bool // set by flag
Expand Down Expand Up @@ -230,8 +231,8 @@ func (G *Generator) initStaticFiles() []error {
// baseDir should always be an absolute path
baseDir := G.CueModuleRoot
// lookup in vendor directory, this will need to change once CUE uses a shared cache in the user homedir
if G.PackageName != "" {
baseDir = filepath.Join(G.CueModuleRoot, CUE_VENDOR_DIR, G.PackageName)
if G.ModuleName != "" {
baseDir = filepath.Join(G.CueModuleRoot, CUE_VENDOR_DIR, G.ModuleName)
}

// Start with static file globs
Expand All @@ -243,7 +244,7 @@ func (G *Generator) initStaticFiles() []error {
fullTrimDir := filepath.Join(baseDir, prefix)
_, err := os.Stat(fullTrimDir)
if err != nil {
fmt.Printf("warning: from %s, directory %s not found, for gen %s:%s, if you do not intend to use static files, set 'Statics: []'\n", baseDir, prefix, G.PackageName, G.Hof.Path)
fmt.Printf("warning: from %s, directory %s not found, for gen %s:%s, if you do not intend to use static files, set 'Statics: []'\n", baseDir, prefix, G.ModuleName, G.Hof.Path)
continue
}

Expand Down Expand Up @@ -367,8 +368,8 @@ func (G *Generator) initPartials() []error {
// baseDir should always be an absolute path
baseDir := G.CueModuleRoot
// lookup in vendor directory, this will need to change once CUE uses a shared cache in the user homedir
if G.PackageName != "" {
baseDir = filepath.Join(G.CueModuleRoot, CUE_VENDOR_DIR, G.PackageName)
if G.ModuleName != "" {
baseDir = filepath.Join(G.CueModuleRoot, CUE_VENDOR_DIR, G.ModuleName)
}

// then partials from disk via globs
Expand All @@ -379,7 +380,7 @@ func (G *Generator) initPartials() []error {
fullTrimDir := filepath.Join(baseDir, prefix)
_, err := os.Stat(fullTrimDir)
if err != nil {
fmt.Printf("warning: from %s, directory %s not found, for gen %s:%s, if you do not intend to use partials files, set 'Partials: []'\n", baseDir, prefix, G.PackageName, G.Hof.Path)
fmt.Printf("warning: from %s, directory %s not found, for gen %s:%s, if you do not intend to use partials files, set 'Partials: []'\n", baseDir, prefix, G.ModuleName, G.Hof.Path)
continue
}

Expand Down Expand Up @@ -454,8 +455,8 @@ func (G *Generator) initTemplates() []error {
// baseDir should always be an absolute path
baseDir := G.CueModuleRoot
// lookup in vendor directory, this will need to change once CUE uses a shared cache in the user homedir
if G.PackageName != "" {
baseDir = filepath.Join(G.CueModuleRoot, CUE_VENDOR_DIR, G.PackageName)
if G.ModuleName != "" {
baseDir = filepath.Join(G.CueModuleRoot, CUE_VENDOR_DIR, G.ModuleName)
}

for _, tg := range G.Templates {
Expand All @@ -465,7 +466,7 @@ func (G *Generator) initTemplates() []error {
fullTrimDir := filepath.Join(baseDir, prefix)
_, err := os.Stat(fullTrimDir)
if err != nil {
fmt.Printf("warning: from %s, directory %s not found, for gen %s:%s, if you do not intend to use templates files, set 'Templates: []'\n", baseDir, prefix, G.PackageName, G.Hof.Path)
fmt.Printf("warning: from %s, directory %s not found, for gen %s:%s, if you do not intend to use templates files, set 'Templates: []'\n", baseDir, prefix, G.ModuleName, G.Hof.Path)
continue
}

Expand Down

0 comments on commit c661ae1

Please sign in to comment.