Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
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 @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
22 changes: 16 additions & 6 deletions plugin/plugin_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugin

import (
"errors"
"strings"
)

const (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"}},
}
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
Loading