Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/commands/rhoas_kafka_delete.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Delete a Kafka instance

=== Synopsis

Permanently delete a Kafka instance
Permanently deletes a Kafka instance

....
rhoas kafka delete [flags]
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/rhoas_kafka_list.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rhoas kafka list [flags]
....
-h, --help help for list
--limit int Limit of items that should be returned from server (default 100)
-o, --output string Format to display the Kafka instances. Choose from: "json", "yaml", "yml", "table" (default "table")
-o, --output string Output format of the results. Options: +["plain" "json" "yml" "yaml"] (default "plain")
--page int Page that should be returned from server
....

Expand Down
2 changes: 1 addition & 1 deletion docs/commands/rhoas_kafka_topics_list.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ rhoas kafka topics list [flags]
=== Options

....
-o, --Output string The output format as 'plain-text', 'json', or 'yaml' (default "plain-text")
-h, --help help for list
--insecure Enables insecure communication with the server. This disables verification of TLS certificates and host names.
-o, --output string Output format of the results. Options: +["plain" "json" "yml" "yaml"] (default "plain")
....

=== Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/rhoas_serviceaccount_list.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $ rhoas serviceaccount list -o json

....
-h, --help help for list
-o, --output string Format to display the service accounts. Available options: ["table" "json" "yml" "yaml"] (default "table")
-o, --output string Output format of the results. Options: +["plain" "json" "yml" "yaml"] (default "plain")
....

=== Options inherited from parent commands
Expand Down
16 changes: 12 additions & 4 deletions pkg/cmd/kafka/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"strconv"

flagutil "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmdutil/flags"

"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/dump"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -48,15 +50,21 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
Long: "List all Kafka instances",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
if opts.outputFormat != "json" && opts.outputFormat != "yaml" && opts.outputFormat != "yml" && opts.outputFormat != "table" {
return fmt.Errorf("Invalid output format '%v'", opts.outputFormat)
logger, err := opts.Logger()
if err != nil {
return err
}

if !flagutil.IsValidInput(opts.outputFormat, flagutil.AllowedListFormats...) {
logger.Infof("Unknown flag value '%v' for --output. Using plain format instead", opts.outputFormat)
opts.outputFormat = "plain"
}

return runList(opts)
},
}

cmd.Flags().StringVarP(&opts.outputFormat, "output", "o", "table", "Format to display the Kafka instances. Choose from: \"json\", \"yaml\", \"yml\", \"table\"")
cmd.Flags().StringVarP(&opts.outputFormat, "output", "o", "plain", fmt.Sprintf("Output format of the results. Choose from %q", flagutil.AllowedListFormats))
cmd.Flags().IntVarP(&opts.page, "page", "", 0, "Page that should be returned from server")
cmd.Flags().IntVarP(&opts.limit, "limit", "", 100, "Limit of items that should be returned from server")
return cmd
Expand Down Expand Up @@ -96,7 +104,7 @@ func runList(opts *options) error {
outputFormat := opts.outputFormat

if err = json.Unmarshal(jsonResponse, &kafkaList); err != nil {
logger.Infof("Could not unmarshal Kakfa items into table, defaulting to JSON: %v", err)
logger.Infof("Could not unmarshal Kakfa list into table, defaulting to JSON: %v", err)
outputFormat = "json"
}

Expand Down
11 changes: 10 additions & 1 deletion pkg/cmd/kafka/topics/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/bf2fc6cc711aee1a0c2a/cli/internal/config"
"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmd/factory"
flagutil "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmdutil/flags"
"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/connection"
"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/logging"
"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/sdk/kafka/topics"
Expand Down Expand Up @@ -33,11 +34,19 @@ func NewListTopicCommand(f *factory.Factory) *cobra.Command {
Short: "List topics",
Long: "List all topics in the current selected Managed Kafka cluster",
RunE: func(cmd *cobra.Command, _ []string) error {
logger, err := opts.Logger()
if err != nil {
return err
}
if flagutil.IsValidInput(opts.output, flagutil.AllowedListFormats...) {
logger.Infof("Unknown flag value '%v' for --output. Using table format instead", opts.output)
opts.output = "plain"
}
return listTopic(opts)
},
}

cmd.Flags().StringVarP(&opts.output, "Output", "o", "plain-text", "The output format as 'plain-text', 'json', or 'yaml'")
cmd.Flags().StringVarP(&opts.output, "output", "o", "plain", fmt.Sprintf("Output format of the results. Choose from %q", flagutil.AllowedListFormats))
cmd.Flags().BoolVar(&opts.insecure, "insecure", false, "Enables insecure communication with the server. This disables verification of TLS certificates and host names.")
return cmd
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/cmd/serviceaccount/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
}

if !flagutil.IsValidInput(opts.output, flagutil.AllowedListFormats...) {
logger.Debugf("Unknown flag value '%v' for --output. Using table format instead", opts.output)
opts.output = "table"
logger.Infof("Unknown flag value '%v' for --output. Using table format instead", opts.output)
opts.output = "plain"
}

return runList(opts)
},
}

cmd.Flags().StringVarP(&opts.output, "output", "o", "table", fmt.Sprintf("Format to display the service accounts. Available options: %+q", flagutil.AllowedListFormats))
cmd.Flags().StringVarP(&opts.output, "output", "o", "plain", fmt.Sprintf("Output format of the results. Choose from %q", flagutil.AllowedListFormats))

return cmd
}
Expand Down Expand Up @@ -97,7 +98,7 @@ func runList(opts *Options) (err error) {
}

var tableList []table
if opts.output == "table" {
if opts.output == "plain" {
jsonResponse, _ := json.Marshal(serviceaccounts)

if err = json.Unmarshal(jsonResponse, &tableList); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmdutil/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
AllowedListFormats = []string{"table", "json", "yml", "yaml"}
AllowedListFormats = []string{"plain", "json", "yml", "yaml"}
CredentialsOutputFormats = []string{"env", "properties", "json", "kafka", "kube"}
)

Expand Down