Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ func (g *Generator) Generate(dir string, format Format) error {
}
}

func (g *Generator) GenerateJSON(dir string, format Format) error {
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return err
}
switch format {
case FormatJSON:
return g.renderTablesAsJSON(dir)
default:
return fmt.Errorf("unsupported format: %v", format)
}
}

// setDestinationManagedCqColumns overwrites or adds the CQ columns that are managed by the destination plugins (_cq_sync_time, _cq_source_name).
// func setDestinationManagedCqColumns(tables []*schema.Table) {
// for _, table := range tables {
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_plugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/samber/lo v1.47.0 // indirect
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/cobra v1.9.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/thoas/go-funk v0.9.3 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
Expand Down
10 changes: 5 additions & 5 deletions examples/simple_plugin/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ github.com/cloudquery/plugin-pb-go v1.26.9/go.mod h1:euhtVJKRtmWzukBxOjJyCKHPU9O
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=
github.com/cloudquery/plugin-sdk/v2 v2.7.0/go.mod h1:pAX6ojIW99b/Vg4CkhnsGkRIzNaVEceYMR+Bdit73ug=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -142,10 +142,10 @@ github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/cobra v1.9.0 h1:Py5fIuq/lJsRYxcxfOtsJqpmwJWCMOUy2tMJYV8TNHE=
github.com/spf13/cobra v1.9.0/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/rs/zerolog v1.33.0
github.com/samber/lo v1.47.0
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1
github.com/spf13/cobra v1.8.1
github.com/spf13/cobra v1.9.0
github.com/stretchr/testify v1.10.0
github.com/thoas/go-funk v0.9.3
go.opentelemetry.io/otel v1.34.0
Expand Down Expand Up @@ -81,7 +81,7 @@ require (
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ github.com/cloudquery/plugin-pb-go v1.26.9/go.mod h1:euhtVJKRtmWzukBxOjJyCKHPU9O
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=
github.com/cloudquery/plugin-sdk/v2 v2.7.0/go.mod h1:pAX6ojIW99b/Vg4CkhnsGkRIzNaVEceYMR+Bdit73ug=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -144,10 +144,10 @@ github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/cobra v1.9.0 h1:Py5fIuq/lJsRYxcxfOtsJqpmwJWCMOUy2tMJYV8TNHE=
github.com/spf13/cobra v1.9.0/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
Expand Down
9 changes: 5 additions & 4 deletions serve/docs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package serve

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -43,11 +44,11 @@ func (s *PluginServe) newCmdPluginDoc() *cobra.Command {
return err
}
g := docs.NewGenerator(s.plugin.Name(), tables)
f := docs.FormatMarkdown
if format.Value == "json" {
f = docs.FormatJSON
if format.Value != "json" {
return errors.New("only json format is supported. If need to generate markdown, use the `cloudquery tables` command")
}
return g.Generate(args[0], f)

return g.GenerateJSON(args[0], docs.FormatJSON)
},
}
cmd.Flags().Var(format, "format", fmt.Sprintf("output format. one of: %s", strings.Join(format.Allowed, ",")))
Expand Down
2 changes: 1 addition & 1 deletion serve/docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestPluginDocs(t *testing.T) {
memdb.NewMemDBClient)
srv := Plugin(p)
cmd := srv.newCmdPluginRoot()
cmd.SetArgs([]string{"doc", tmpDir})
cmd.SetArgs([]string{"doc", tmpDir, "--format", "json"})
if err := cmd.Execute(); err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 10 additions & 2 deletions serve/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s *PluginServe) writeTablesJSON(ctx context.Context, dir string) error {
return os.WriteFile(outputPath, buffer.Bytes(), 0644)
}

func (s *PluginServe) build(pluginDirectory string, target plugin.BuildTarget, distPath, pluginVersion string) (*TargetBuild, error) {
func (s *PluginServe) build(pluginDirectory string, target plugin.BuildTarget, distPath, pluginVersion, buildTags string) (*TargetBuild, error) {
pluginFileName := fmt.Sprintf("plugin-%s-%s-%s-%s", s.plugin.Name(), pluginVersion, target.OS, target.Arch)
pluginPath := path.Join(distPath, pluginFileName)
importPath, err := s.getModuleName(pluginDirectory)
Expand All @@ -132,6 +132,9 @@ func (s *PluginServe) build(pluginDirectory string, target plugin.BuildTarget, d
args := []string{"build", "-o", pluginPath}
args = append(args, "-buildmode=exe")
args = append(args, "-ldflags", ldFlags)
// This disables gRPC tracing, which introduces a dependency that blocks dead code elimination\
Comment thread
bbernays marked this conversation as resolved.
Outdated
// https://github.com/grpc/grpc-go/blob/030938e543b4a721cd426d15611d50ecf097dcf3/trace_notrace.go#L23-L25
args = append(args, "-tags", buildTags)
cmd := exec.Command("go", args...)
cmd.Dir = pluginDirectory
cmd.Stdout = os.Stdout
Expand Down Expand Up @@ -401,6 +404,10 @@ func (s *PluginServe) newCmdPluginPackage() *cobra.Command {
message = string(messageBytes)
}
message = normalizeMessage(message)
buildTags := "grpcnotrace"
if cmd.Flag("build-tags").Changed {
buildTags = cmd.Flag("build-tags").Value.String()
}

if err := os.MkdirAll(distPath, 0755); err != nil {
return err
Expand Down Expand Up @@ -434,7 +441,7 @@ func (s *PluginServe) newCmdPluginPackage() *cobra.Command {
targets := []TargetBuild{}
for _, target := range s.plugin.Targets() {
fmt.Println("Building for OS: " + target.OS + ", ARCH: " + target.Arch)
targetBuild, err := s.build(pluginDirectory, target, distPath, pluginVersion)
targetBuild, err := s.build(pluginDirectory, target, distPath, pluginVersion, buildTags)
if err != nil {
return fmt.Errorf("failed to build plugin for %s/%s: %w", target.OS, target.Arch, err)
}
Expand All @@ -455,6 +462,7 @@ func (s *PluginServe) newCmdPluginPackage() *cobra.Command {
cmd.Flags().StringP("dist-dir", "D", "", "dist directory to output the built plugin. (default: <plugin_directory>/dist)")
cmd.Flags().StringP("docs-dir", "", "", "docs directory containing markdown files to copy to the dist directory. (default: <plugin_directory>/docs)")
cmd.Flags().StringP("message", "m", "", "message that summarizes what is new or changed in this version. Use @<file> to read from file. Supports markdown.")
cmd.Flags().StringP("build-tags", "", "", "build tags to use when building the plugin. (default: grpcnotrace)")
Comment thread
bbernays marked this conversation as resolved.
Outdated
return cmd
}

Expand Down