Skip to content

Commit

Permalink
add include import optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored and Pantani committed May 21, 2024
1 parent ec78d89 commit 8be7c15
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
36 changes: 28 additions & 8 deletions ignite/pkg/cosmosbuf/buf.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ type (

// genOptions used to configure code generation.
genOptions struct {
excluded []glob.Glob
fileByFile bool
flags map[string]string
excluded []glob.Glob
fileByFile bool
flags map[string]string
includeImports string
includeWKT string
}

// GenOption configures code generation.
Expand All @@ -72,9 +74,11 @@ type (

func newGenOptions() genOptions {
return genOptions{
flags: make(map[string]string),
excluded: make([]glob.Glob, 0),
fileByFile: false,
flags: make(map[string]string),
excluded: make([]glob.Glob, 0),
fileByFile: false,
includeWKT: "false",
includeImports: "false",
}
}

Expand All @@ -94,6 +98,22 @@ func ExcludeFiles(patterns ...string) GenOption {
}
}

// IncludeImports also generate all imports except for Well-Known Types

Check failure on line 101 in ignite/pkg/cosmosbuf/buf.go

View workflow job for this annotation

GitHub Actions / Lint Go code

Comment should end in a period (godot)
func IncludeImports() GenOption {
return func(o *genOptions) {
o.includeImports = "true"

Check failure on line 104 in ignite/pkg/cosmosbuf/buf.go

View workflow job for this annotation

GitHub Actions / Lint Go code

string `true` has 3 occurrences, make it a constant (goconst)
}
}

// IncludeWKT also generate Well-Known Types.
// Cannot be set to true without setting --include-imports to true

Check failure on line 109 in ignite/pkg/cosmosbuf/buf.go

View workflow job for this annotation

GitHub Actions / Lint Go code

Comment should end in a period (godot)
func IncludeWKT() GenOption {
return func(o *genOptions) {
o.includeImports = "true"
o.includeWKT = "true"
}
}

// FileByFile runs the generate command for each proto file.
func FileByFile() GenOption {
return func(o *genOptions) {
Expand Down Expand Up @@ -206,8 +226,8 @@ func (b Buf) Generate(
flagOutput: output,
flagErrorFormat: fmtJSON,
flagLogFormat: fmtJSON,
flagIncludeImports: "true",
flagIncludeWellKnownTypes: "true",
flagIncludeImports: opts.includeImports,
flagIncludeWellKnownTypes: opts.includeWKT,
}
for k, v := range opts.flags {
flags[k] = v
Expand Down
9 changes: 8 additions & 1 deletion ignite/pkg/cosmosgen/generate_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ func (g *generator) generate(ctx context.Context, template, fromPath string, exc
defer os.RemoveAll(tmp)

// code generate for each module.
if err := g.buf.Generate(ctx, g.protoPath(), tmp, template, cosmosbuf.ExcludeFiles(excluded...)); err != nil {
if err := g.buf.Generate(
ctx,
g.protoPath(),
tmp,
template,
cosmosbuf.ExcludeFiles(excluded...),
cosmosbuf.IncludeWKT(),
); err != nil {
return err
}

Expand Down
1 change: 1 addition & 0 deletions ignite/pkg/cosmosgen/generate_typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (g *tsGenerator) generateModuleTemplate(
typesOut,
g.g.tsTemplate(),
cosmosbuf.ExcludeFiles("module.proto"),
cosmosbuf.IncludeWKT(),
); err != nil {
return err
}
Expand Down

0 comments on commit 8be7c15

Please sign in to comment.