|
| 1 | +# conn-sdk-cli |
| 2 | + |
| 3 | +`conn-sdk-cli` is a CLI tool that helps with development of connectors. To |
| 4 | +install the tool, run: |
| 5 | + |
| 6 | +```shell |
| 7 | +go install github.com/conduitio/conduit-connector-sdk/conn-sdk-cli@latest |
| 8 | +``` |
| 9 | + |
| 10 | +For more information about using the available commands, run: |
| 11 | + |
| 12 | +```shell |
| 13 | +conn-sdk-cli help |
| 14 | +``` |
| 15 | + |
| 16 | +or the following for a specific command: |
| 17 | + |
| 18 | +```shell |
| 19 | +conn-sdk-cli <command> --help |
| 20 | +``` |
| 21 | + |
| 22 | +The following sections describe the most important commands in more details. |
| 23 | + |
| 24 | +## readmegen |
| 25 | + |
| 26 | +The `readmegen` command is used to generate sections in a README file that |
| 27 | +document the connector. `readmegen` searches for certain tags in the README file |
| 28 | +and replaces them with appropriate values. For example, if |
| 29 | +`<!-- readmegen:name -->` is found in a README, then `readmegen` will replace it |
| 30 | +with the connector name. |
| 31 | + |
| 32 | +Here's the list of supported tags. |
| 33 | + |
| 34 | +* `<!-- readmegen:name -->` - The name of the connector (e.g., "postgres", "mysql"). |
| 35 | + |
| 36 | +* `<!-- readmegen:summary -->` - A brief overview of what the connector does and |
| 37 | + what service/system it connects to. |
| 38 | + |
| 39 | +* `<!-- readmegen:description -->` - Detailed information about the connector's |
| 40 | + functionality, use cases, and any special features. |
| 41 | + |
| 42 | +* `<!-- readmegen:version -->` - The version of the connector. |
| 43 | + |
| 44 | +* `<!-- readmegen:author -->` - The name(s) of the connector's developer(s) or |
| 45 | + maintaining organization. |
| 46 | + |
| 47 | +* `<!-- readmegen:source.parameters.yaml -->` - Configuration parameters for the |
| 48 | + connector when acting as a source (reading data), rendered in YAML format. The |
| 49 | + YAML code can be used in a pipeline. |
| 50 | + |
| 51 | +* `<!-- readmegen:source.parameters.table -->` - Source configuration parameters |
| 52 | + formatted as a table. |
| 53 | + |
| 54 | +* `<!-- readmegen:destination.parameters.yaml -->` - Configuration parameters |
| 55 | + for the connector when acting as a destination (writing data), rendered in |
| 56 | + YAML format. The YAML code can be used in a pipeline. |
| 57 | + |
| 58 | +* `<!-- readmegen:destination.parameters.table -->` - Destination configuration |
| 59 | + parameters formatted as a table. |
| 60 | + |
| 61 | +## specgen |
| 62 | + |
| 63 | +The `specgen` command updates the source and destination parameters in the |
| 64 | +`connector.yaml` by using the configuration structs from the code. |
| 65 | + |
| 66 | +It's usually run as part of `go generate`. It also needs access to the |
| 67 | +`sdk.Connector` variable that holds references to the constructor functions for |
| 68 | +the source and the destination, so it's best to place it in the `connector.go` |
| 69 | +file. The following is an example from the Kafka connector: |
| 70 | + |
| 71 | +```go |
| 72 | +//go:generate conn-sdk-cli specgen |
| 73 | + |
| 74 | +// Package kafka contains implementations for Kafka source and destination |
| 75 | +// connectors for Conduit. |
| 76 | +package kafka |
| 77 | + |
| 78 | +import ( |
| 79 | + _ "embed" |
| 80 | + |
| 81 | + sdk "github.com/conduitio/conduit-connector-sdk" |
| 82 | +) |
| 83 | + |
| 84 | +//go:embed connector.yaml |
| 85 | +var specs string |
| 86 | + |
| 87 | +var version = "(devel)" |
| 88 | + |
| 89 | +var Connector = sdk.Connector{ |
| 90 | + NewSpecification: sdk.YAMLSpecification(specs, version), |
| 91 | + NewSource: NewSource, |
| 92 | + NewDestination: NewDestination, |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +If you run `conn-sdk-cli specgen` (directly, through `go generate ./...`, with |
| 97 | +`make generate` that's provided by the connector template), you'll see that the |
| 98 | +`connector.yaml` is updated with the source and/or destination parameters. |
0 commit comments