-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathdocs.go
55 lines (49 loc) · 1.42 KB
/
docs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package serve
import (
"fmt"
"strings"
"github.com/cloudquery/plugin-sdk/v4/docs"
"github.com/cloudquery/plugin-sdk/v4/plugin"
"github.com/spf13/cobra"
)
const (
pluginDocShort = "Generate documentation for tables"
pluginDocLong = `Generate documentation for tables
If format is markdown, a destination directory will be created (if necessary) containing markdown files.
Example:
doc ./output
If format is JSON, a destination directory will be created (if necessary) with a single json file called __tables.json.
Example:
doc --format json .
`
)
func (s *PluginServe) newCmdPluginDoc() *cobra.Command {
format := newEnum([]string{"json", "markdown"}, "markdown")
cmd := &cobra.Command{
Use: "doc <directory>",
Short: pluginDocShort,
Long: pluginDocLong,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := s.plugin.Init(cmd.Context(), nil, plugin.NewClientOptions{
NoConnection: true,
}); err != nil {
return err
}
tables, err := s.plugin.Tables(cmd.Context(), plugin.TableOptions{
Tables: []string{"*"},
})
if err != nil {
return err
}
g := docs.NewGenerator(s.plugin.Name(), tables)
f := docs.FormatMarkdown
if format.Value == "json" {
f = docs.FormatJSON
}
return g.Generate(args[0], f)
},
}
cmd.Flags().Var(format, "format", fmt.Sprintf("output format. one of: %s", strings.Join(format.Allowed, ",")))
return cmd
}