| 33 | } |
| 34 | |
| 35 | func tablesV3(ctx context.Context, sourceClient *managedplugin.Client, sourceSpec *specs.Source, path, format, filter string) error { |
| 36 | err := registerOnce() |
| 37 | if err != nil { |
| 38 | return err |
| 39 | } |
| 40 | sourcePbClient := pluginPb.NewPluginClient(sourceClient.Conn) |
| 41 | if err := initPlugin(ctx, sourcePbClient, sourceSpec.Spec, true, invocationUUID.String()); err != nil { |
| 42 | return fmt.Errorf("failed to init source: %w", err) |
| 43 | } |
| 44 | |
| 45 | name, err := sourcePbClient.GetName(ctx, &pluginPb.GetName_Request{}) |
| 46 | if err != nil { |
| 47 | return fmt.Errorf("failed to get source name: %w", err) |
| 48 | } |
| 49 | |
| 50 | req := &pluginPb.GetTables_Request{ |
| 51 | Tables: []string{"*"}, |
| 52 | } |
| 53 | |
| 54 | if filter == "spec" { |
| 55 | req.Tables = sourceSpec.Tables |
| 56 | req.SkipTables = sourceSpec.SkipTables |
| 57 | req.SkipDependentTables = *sourceSpec.SkipDependentTables |
| 58 | } |
| 59 | |
| 60 | tables, err := getTables(ctx, sourcePbClient, req) |
| 61 | if err != nil { |
| 62 | return fmt.Errorf("failed to convert schemas to tables: %w", err) |
| 63 | } |
| 64 | topLevelTables, err := tables.UnflattenTables() |
| 65 | if err != nil { |
| 66 | return fmt.Errorf("failed to unflatten tables: %w", err) |
| 67 | } |
| 68 | |
| 69 | g := docs.NewGenerator(name.Name, topLevelTables) |
| 70 | f := docs.FormatMarkdown |
| 71 | if format == "json" { |
| 72 | f = docs.FormatJSON |
| 73 | } |
| 74 | return g.Generate(path, f) |
| 75 | } |