Skip to content

Commit

Permalink
Add specs and version command (#253)
Browse files Browse the repository at this point in the history
* add specs command

* output specs v1

* version command

* print command
  • Loading branch information
lovromazgon authored Jan 31, 2025
1 parent dc09aab commit 61e614b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"github.com/conduitio/conduit-connector-protocol/pconnector"
"github.com/conduitio/conduit-connector-protocol/pconnector/server"
"github.com/conduitio/conduit-connector-protocol/pconnutils"
v1 "github.com/conduitio/conduit-connector-sdk/conn-sdk-cli/specgen/model/v1"
"github.com/conduitio/conduit-connector-sdk/internal"
"github.com/conduitio/yaml/v3"
"github.com/rs/zerolog"
)

Expand All @@ -37,13 +39,38 @@ import (
//
// Plugins should call Serve in their main() functions.
func Serve(c Connector) {
handleCommand(c, os.Args[1:])

err := serve(c)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "error running plugin: %+v", err)
os.Exit(1)
}
}

func handleCommand(c Connector, args []string) {
if len(args) == 0 {
return
}

switch args[0] {
case "spec", "specs", "specification", "specifications":
spec := v1.Specification{}.FromConfig(c.NewSpecification())
out, err := yaml.Marshal(spec)
if err != nil {
panic(fmt.Errorf("failed to marshal specification: %w", err))
}
fmt.Println(string(out))
os.Exit(0)
case "version":
fmt.Println(c.NewSpecification().Version)
os.Exit(0)
default:
fmt.Println("unknown command:", args[0])
os.Exit(1)
}
}

func serve(c Connector) error {
cfg, err := getPluginConfig()
if err != nil {
Expand Down

0 comments on commit 61e614b

Please sign in to comment.