Skip to content

Commit

Permalink
feat(generate): add ability to generate multiple targeted packages
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderblue committed Sep 27, 2024
1 parent a5b70a6 commit 5777209
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
81 changes: 81 additions & 0 deletions pkg/accountmanagement/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/generate/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (

var (
packageName string
packageNames []string
refetch bool
includeIntegrationTest bool
)
Expand All @@ -34,6 +35,7 @@ is up to date with your configured GraphQL API.
Run: func(cmd *cobra.Command, args []string) {
util.LogIfError(log.ErrorLevel, Generate(GeneratorOptions{
PackageName: packageName,
PackageNames: packageNames,
Refetch: refetch,
IncludeIntegrationTest: includeIntegrationTest,
}))
Expand All @@ -42,6 +44,7 @@ is up to date with your configured GraphQL API.

func init() {
Command.Flags().StringVarP(&packageName, "package", "p", "", "Go package name for the generated files")
Command.Flags().StringSliceVar(&packageNames, "packages", []string{}, "List of package names to generate. Example: --packages=package1,package2")

Command.Flags().StringP("schema", "s", fetch.DefaultSchemaCacheFile, "Schema file to read from")
util.LogIfError(log.ErrorLevel, viper.BindPFlag("schema_file", Command.Flags().Lookup("schema")))
Expand Down
11 changes: 11 additions & 0 deletions pkg/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

type GeneratorOptions struct {
PackageName string
PackageNames []string
Refetch bool
IncludeIntegrationTest bool
}
Expand Down Expand Up @@ -76,6 +77,16 @@ func Generate(options GeneratorOptions) error {
return generateForPackage(options.PackageName, cfg, s, options.IncludeIntegrationTest)
}

if options.PackageNames != nil {
for _, packageName := range options.PackageNames {
if err := generateForPackage(packageName, cfg, s, options.IncludeIntegrationTest); err != nil {
return err
}
}

return nil
}

// Generate for all configured packages
for _, pkgConfig := range cfg.Packages {
if err := generateForPackage(pkgConfig.Name, cfg, s, options.IncludeIntegrationTest); err != nil {
Expand Down

0 comments on commit 5777209

Please sign in to comment.