Skip to content

Commit

Permalink
Add properties format print
Browse files Browse the repository at this point in the history
change default format to properties
  • Loading branch information
lala7573 committed Mar 29, 2021
1 parent 2c66b1f commit 222b708
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
A command line interface (CLI) around the Kafka Connect REST Interface to manage connectors without any dependency.

## Installation

```
brew install lala7573/homebrew-tap/kafka-connect-cli
```
Expand All @@ -29,7 +30,7 @@ Available Commands:

Flags:
-e, --endpoint string kafka connect rest (default "http://localhost:8083/")
-f, --format string format: properties | json (default "json")
-f, --format string format: properties | json (default "properties")
-h, --help help for ./kafka-connect-cli

Use "./kafka-connect-cli [command] --help" for more information about a command.
Expand Down
28 changes: 20 additions & 8 deletions kafkaConnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,31 @@ func HandleResponse(resp *http.Response) {
return
}

// handle if config
var connectorConfig ConnectorConfig;
if err = json.Unmarshal(body, &connectorConfig); err == nil && connectorConfig.Name != "" {
if config.FORMAT == "json" {
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(connectorConfig)
} else if (config.FORMAT == "properties") {
configStr := fmt.Sprintf("name=%s\n", connectorConfig.Name);
for k, v := range connectorConfig.Config {
configStr += fmt.Sprintf("%s=%s\n", k, v)
}
fmt.Fprintf(os.Stdout, configStr)
}
return;
}

var obj interface{}
if err = json.Unmarshal(body, &obj); err != nil {
log.Fatal("Failed to print json", err)
return
}

if config.FORMAT == "json" {
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(obj)
} else if (config.FORMAT == "properties") {
fmt.Println("unsupported")
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(obj)
}

type ConnectorConfig struct {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func getenv(key string, defaultVal string) string {
return defaultVal
}

const version = "0.0.1"
const version = "0.0.2"
var cmdVersion = &cobra.Command{
Use: "version",
Short: "Version",
Expand All @@ -26,7 +26,7 @@ var cmdVersion = &cobra.Command{
func main() {
cmdRoot := &cobra.Command{Use: os.Args[0]}
cmdRoot.PersistentFlags().StringVarP(&config.KAFKA_CONNECT_REST, "endpoint", "e", getenv("KAFKA_CONNECT_REST", "http://localhost:8083/"), "kafka connect rest")
cmdRoot.PersistentFlags().StringVarP(&config.FORMAT, "format", "f", "json", "format: properties | json")
cmdRoot.PersistentFlags().StringVarP(&config.FORMAT, "format", "f", "properties", "format: properties | json")

cmdRoot.AddCommand(cmdPlugins)
cmdRoot.AddCommand(cmdConnectorList)
Expand Down

0 comments on commit 222b708

Please sign in to comment.