diff --git a/docs/generator.go b/docs/generator.go index 62dba4f67b..bb4e762699 100644 --- a/docs/generator.go +++ b/docs/generator.go @@ -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 { diff --git a/examples/simple_plugin/go.mod b/examples/simple_plugin/go.mod index 1a31766385..5a3399bc72 100644 --- a/examples/simple_plugin/go.mod +++ b/examples/simple_plugin/go.mod @@ -59,8 +59,8 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/samber/lo v1.49.1 // 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 diff --git a/examples/simple_plugin/go.sum b/examples/simple_plugin/go.sum index a1c60878f8..fad9398f94 100644 --- a/examples/simple_plugin/go.sum +++ b/examples/simple_plugin/go.sum @@ -59,7 +59,7 @@ github.com/cloudquery/plugin-pb-go v1.26.11/go.mod h1:S65IWZQejnUHxY/411F+vTt/9T 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= @@ -144,10 +144,10 @@ github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew= github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o= 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= diff --git a/go.mod b/go.mod index cc5bb813fd..2df0d61740 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/rs/zerolog v1.34.0 github.com/samber/lo v1.49.1 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 @@ -82,7 +82,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 diff --git a/go.sum b/go.sum index a76cd0be76..27d97b23c5 100644 --- a/go.sum +++ b/go.sum @@ -61,7 +61,7 @@ github.com/cloudquery/plugin-pb-go v1.26.11/go.mod h1:S65IWZQejnUHxY/411F+vTt/9T 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= @@ -146,10 +146,10 @@ github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew= github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o= 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= diff --git a/plugin/plugin_package.go b/plugin/plugin_package.go index 663481b990..7547c7d5f4 100644 --- a/plugin/plugin_package.go +++ b/plugin/plugin_package.go @@ -2,6 +2,7 @@ package plugin import ( "errors" + "strings" ) const ( @@ -41,14 +42,23 @@ type BuildTarget struct { Arch string `json:"arch"` CGO bool `json:"cgo"` Env []string `json:"env"` + Tags []string `json:"tags"` IncludeSymbols bool `json:"include_symbols"` } func (t BuildTarget) EnvVariables() []string { - variables := append(t.cgoEnvVariables(), "GOOS="+t.OS, "GOARCH="+t.Arch) + variables := append(t.cgoEnvVariables(), "GOOS="+t.OS, "GOARCH="+t.Arch, t.tags()) return append(variables, t.Env...) } +func (t BuildTarget) tags() string { + if len(t.Tags) == 0 { + return "" + } + tagString := strings.Join(t.Tags, ",") + return "GOFLAGS=-tags=" + tagString +} + func (t BuildTarget) cgoEnvVariables() []string { // default is to tool at the param. Can be overridden by adding `CGO_ENABLED=1` to BuildTarget.Env if !t.CGO { @@ -78,9 +88,9 @@ func (t BuildTarget) cgoEnvVariables() []string { } var DefaultBuildTargets = []BuildTarget{ - {OS: GoOSLinux, Arch: GoArchAmd64}, - {OS: GoOSLinux, Arch: GoArchArm64}, - {OS: GoOSWindows, Arch: GoArchAmd64}, - {OS: GoOSDarwin, Arch: GoArchAmd64}, - {OS: GoOSDarwin, Arch: GoArchArm64}, + {OS: GoOSLinux, Arch: GoArchAmd64, Tags: []string{"grpcnotrace"}}, + {OS: GoOSLinux, Arch: GoArchArm64, Tags: []string{"grpcnotrace"}}, + {OS: GoOSWindows, Arch: GoArchAmd64, Tags: []string{"grpcnotrace"}}, + {OS: GoOSDarwin, Arch: GoArchAmd64, Tags: []string{"grpcnotrace"}}, + {OS: GoOSDarwin, Arch: GoArchArm64, Tags: []string{"grpcnotrace"}}, } diff --git a/serve/docs.go b/serve/docs.go index 9cab2d3bcd..db5bb56a93 100644 --- a/serve/docs.go +++ b/serve/docs.go @@ -1,6 +1,7 @@ package serve import ( + "errors" "fmt" "strings" @@ -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, ","))) diff --git a/serve/docs_test.go b/serve/docs_test.go index df463dcc8f..30a3e605f4 100644 --- a/serve/docs_test.go +++ b/serve/docs_test.go @@ -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) }