Skip to content

Commit

Permalink
typo
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyuhang0 committed Dec 14, 2023
1 parent 2930237 commit e193828
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/cli/serverless/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func ListCmd(h *internal.Helper) *cobra.Command {
},
}

listCmd.Flags().StringP(flag.Output, flag.OutputShort, output.HumanFormat, "Output format, One of [\"human\" \"json\"], for the complete result, please use json format")
listCmd.Flags().StringP(flag.Output, flag.OutputShort, output.HumanFormat, "Output format, One of [\"human\" \"json\"]. For the complete result, please use json format")
listCmd.Flags().StringP(flag.ProjectID, flag.ProjectIDShort, "", "The ID of the project")
return listCmd
}
37 changes: 33 additions & 4 deletions internal/cli/serverless/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package serverless

import (
"encoding/json"
"fmt"
"tidbcloud-cli/internal/flag"
"tidbcloud-cli/internal/output"

"tidbcloud-cli/internal"
"tidbcloud-cli/internal/config"
Expand All @@ -39,18 +40,46 @@ func RegionsCmd(h *internal.Helper) *cobra.Command {
return err
}

regions, err := d.ListProviderRegions(serverlessApi.NewServerlessServiceListRegionsParams())
format, err := cmd.Flags().GetString(flag.Output)
if err != nil {
return errors.Trace(err)
}
v, err := json.MarshalIndent(regions.Payload, "", " ")

regions, err := d.ListProviderRegions(serverlessApi.NewServerlessServiceListRegionsParams())
if err != nil {
return errors.Trace(err)
}

fmt.Fprintln(h.IOStreams.Out, string(v))
if format == output.JsonFormat || !h.IOStreams.CanPrompt {
err = output.PrintJson(h.IOStreams.Out, regions.Payload.Regions)
if err != nil {
return errors.Trace(err)
}
} else if format == output.HumanFormat {
columns := []output.Column{
"Name",
"DisplayName",
"Provider",
}

var rows []output.Row
for _, item := range regions.Payload.Regions {
rows = append(rows, output.Row{
*item.Name,
item.DisplayName,
string(*item.Provider),
})
}
err = output.PrintHumanTable(h.IOStreams.Out, columns, rows)
if err != nil {
return errors.Trace(err)
}
} else {
return fmt.Errorf("unsupported output format: %s", format)
}
return nil
},
}
regionsCmd.Flags().StringP(flag.Output, flag.OutputShort, output.HumanFormat, "Output format, One of [\"human\" \"json\"]")
return regionsCmd
}
8 changes: 4 additions & 4 deletions internal/cli/serverless/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ func UpdateCmd(h *internal.Helper) *cobra.Command {
$ %[1]s serverless update
Update displayName of serverless cluster in non-interactive mode:
$ %[1]s serverless update -c <cluster-id> --display-name newClusterName,
$ %[1]s serverless update -c <cluster-id> --display-name newClusterName
Update labels of serverless cluster in non-interactive mode:
$ %[1]s serverless update -c <cluster-id> --labels "{\"label\":\"value2\"}"`, config.CliName),
Update labels of serverless cluster in non-interactive mode:
$ %[1]s serverless update -c <cluster-id> --labels "{\"label1\":\"value1\"}"`, config.CliName),
PreRunE: func(cmd *cobra.Command, args []string) error {
flags := opts.NonInteractiveFlags()
for _, fn := range flags {
Expand Down Expand Up @@ -204,7 +204,7 @@ func UpdateCmd(h *internal.Helper) *cobra.Command {

updateCmd.Flags().StringP(flag.ClusterID, flag.ClusterIDShort, "", "The ID of the cluster to be updated")
updateCmd.Flags().StringP(flag.DisplayName, flag.DisplayNameShort, "", "The displayName of the cluster")
updateCmd.Flags().String(flag.ServerlessLabels, "", "The label of the cluster.\nInteractive example: {\"label1\":\"value1\",\"label1\":\"value1\"}\nNonInteractive example: \"{\\\"label1\\\":\\\"value1\\\",\\\"label2\\\":\\\"value2\\\"}\"")
updateCmd.Flags().String(flag.ServerlessLabels, "", "The label of the cluster.\nInteractive example: {\"label1\":\"value1\",\"label2\":\"value2\"}\nNonInteractive example: \"{\\\"label1\\\":\\\"value1\\\",\\\"label2\\\":\\\"value2\\\"}\"")
updateCmd.Flags().String(flag.ServerlessAnnotations, "", "The annotations of the cluster.\nInteractive example: {\"annotation1\":\"value1\",\"annotation2\":\"value2\"}\nNonInteractive example: \"{\\\"annotation1\\\":\\\"value1\\\",\\\"annotation2\\\":\\\"value2\\\"}\"")
return updateCmd
}
Expand Down

0 comments on commit e193828

Please sign in to comment.