From 73c713ced23e127d9d3644a26c6feac58e4fef13 Mon Sep 17 00:00:00 2001 From: Leon Yang Date: Thu, 19 Jan 2023 16:06:23 +0800 Subject: [PATCH] Use %q instead %v to print slice (#86) --- internal/cli/cluster/create.go | 2 +- internal/cli/cluster/list.go | 2 +- internal/cli/dataimport/list.go | 2 +- internal/cli/dataimport/start/local.go | 4 ++-- internal/cli/dataimport/start/local_test.go | 4 ++-- internal/cli/dataimport/start/s3.go | 4 ++-- internal/cli/dataimport/start/s3_test.go | 2 +- internal/cli/project/list.go | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/cli/cluster/create.go b/internal/cli/cluster/create.go index 1943d21a..688e88f8 100644 --- a/internal/cli/cluster/create.go +++ b/internal/cli/cluster/create.go @@ -281,7 +281,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command { createCmd.Flags().String(flag.ClusterName, "", "Name of the cluster to de created") createCmd.Flags().String(flag.ClusterType, "", "Cluster type, only support \"SERVERLESS\" now") - createCmd.Flags().String(flag.CloudProvider, "", "Cloud provider, one of [AWS]") + createCmd.Flags().String(flag.CloudProvider, "", "Cloud provider, one of [\"AWS\"]") createCmd.Flags().StringP(flag.Region, flag.RegionShort, "", "Cloud region") createCmd.Flags().StringP(flag.ProjectID, flag.ProjectIDShort, "", "The ID of the project, in which the cluster will be created") createCmd.Flags().String(flag.RootPassword, "", "The root password of the cluster") diff --git a/internal/cli/cluster/list.go b/internal/cli/cluster/list.go index 07cf0b6b..fdc92185 100644 --- a/internal/cli/cluster/list.go +++ b/internal/cli/cluster/list.go @@ -142,6 +142,6 @@ 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") return listCmd } diff --git a/internal/cli/dataimport/list.go b/internal/cli/dataimport/list.go index 6d4ce482..11d6c362 100644 --- a/internal/cli/dataimport/list.go +++ b/internal/cli/dataimport/list.go @@ -178,7 +178,7 @@ func ListCmd(h *internal.Helper) *cobra.Command { listCmd.Flags().StringP(flag.ProjectID, flag.ProjectIDShort, "", "Project ID") listCmd.Flags().StringP(flag.ClusterID, flag.ClusterIDShort, "", "Cluster ID") - 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.") return listCmd } diff --git a/internal/cli/dataimport/start/local.go b/internal/cli/dataimport/start/local.go index acb95545..cf2632a6 100644 --- a/internal/cli/dataimport/start/local.go +++ b/internal/cli/dataimport/start/local.go @@ -176,7 +176,7 @@ func LocalCmd(h *internal.Helper) *cobra.Command { clusterID = cmd.Flag(flag.ClusterID).Value.String() dataFormat = cmd.Flag(flag.DataFormat).Value.String() if !util.ElemInSlice(opts.SupportedDataFormats(), dataFormat) { - return fmt.Errorf("data format %s is not supported, please use one of %v", dataFormat, opts.SupportedDataFormats()) + return fmt.Errorf("data format %s is not supported, please use one of %q", dataFormat, opts.SupportedDataFormats()) } targetDatabase = cmd.Flag(flag.TargetDatabase).Value.String() targetTable = cmd.Flag(flag.TargetTable).Value.String() @@ -281,7 +281,7 @@ func LocalCmd(h *internal.Helper) *cobra.Command { localCmd.Flags().StringP(flag.ProjectID, flag.ProjectIDShort, "", "Project ID") localCmd.Flags().StringP(flag.ClusterID, flag.ClusterIDShort, "", "Cluster ID") - localCmd.Flags().String(flag.DataFormat, "", fmt.Sprintf("Data format, one of %v", opts.SupportedDataFormats())) + localCmd.Flags().String(flag.DataFormat, "", fmt.Sprintf("Data format, one of %q", opts.SupportedDataFormats())) localCmd.Flags().String(flag.TargetDatabase, "", "Target database to which import data") localCmd.Flags().String(flag.TargetTable, "", "Target table to which import data") return localCmd diff --git a/internal/cli/dataimport/start/local_test.go b/internal/cli/dataimport/start/local_test.go index 5ea65c59..1f5b0533 100644 --- a/internal/cli/dataimport/start/local_test.go +++ b/internal/cli/dataimport/start/local_test.go @@ -138,7 +138,7 @@ func (suite *LocalImportSuite) TestLocalImportArgs() { { name: "start import with unsupported data format", args: []string{fileName, "--project-id", projectID, "--cluster-id", clusterID, "--data-format", "yaml", "--target-database", targetDatabase, "--target-table", targetTable}, - err: fmt.Errorf("data format yaml is not supported, please use one of [CSV]"), + err: fmt.Errorf("data format yaml is not supported, please use one of [\"CSV\"]"), }, { name: "start import with shorthand flag", @@ -153,7 +153,7 @@ func (suite *LocalImportSuite) TestLocalImportArgs() { { name: "start import without required file path", args: []string{"-p", projectID, "-c", clusterID, "--data-format", dataFormat, "--target-database", targetDatabase, "--target-table", targetTable}, - err: fmt.Errorf("missing argument \n\nUsage:\n start local [flags]\n\nExamples:\n Start an import task in interactive mode:\n $ ticloud import start local \n\n Start an import task in non-interactive mode:\n $ ticloud import start local --project-id --cluster-id --data-format --target-database --target-table \n\t\n Start an import task with custom CSV format:\n $ ticloud import start local --project-id --cluster-id --data-format CSV --target-database --target-table --separator \\\" --delimiter \\' --backslash-escape=false --trim-last-separator=true\n\n\nFlags:\n -c, --cluster-id string Cluster ID\n --data-format string Data format, one of [CSV]\n -h, --help help for local\n -p, --project-id string Project ID\n --target-database string Target database to which import data\n --target-table string Target table to which import data\n\nGlobal Flags:\n --backslash-escape In CSV file whether to parse backslash inside fields as escape characters (default true)\n --delimiter string The delimiter used for quoting of CSV file (default \"\\\"\")\n --separator string The field separator of CSV file (default \",\")\n --trim-last-separator In CSV file whether to treat Separator as the line terminator and trim all trailing separators\n"), + err: fmt.Errorf("missing argument \n\nUsage:\n start local [flags]\n\nExamples:\n Start an import task in interactive mode:\n $ ticloud import start local \n\n Start an import task in non-interactive mode:\n $ ticloud import start local --project-id --cluster-id --data-format --target-database --target-table \n\t\n Start an import task with custom CSV format:\n $ ticloud import start local --project-id --cluster-id --data-format CSV --target-database --target-table --separator \\\" --delimiter \\' --backslash-escape=false --trim-last-separator=true\n\n\nFlags:\n -c, --cluster-id string Cluster ID\n --data-format string Data format, one of [\"CSV\"]\n -h, --help help for local\n -p, --project-id string Project ID\n --target-database string Target database to which import data\n --target-table string Target table to which import data\n\nGlobal Flags:\n --backslash-escape In CSV file whether to parse backslash inside fields as escape characters (default true)\n --delimiter string The delimiter used for quoting of CSV file (default \"\\\"\")\n --separator string The field separator of CSV file (default \",\")\n --trim-last-separator In CSV file whether to treat Separator as the line terminator and trim all trailing separators\n"), }, } diff --git a/internal/cli/dataimport/start/s3.go b/internal/cli/dataimport/start/s3.go index 8d643757..90f1841e 100644 --- a/internal/cli/dataimport/start/s3.go +++ b/internal/cli/dataimport/start/s3.go @@ -179,7 +179,7 @@ func S3Cmd(h *internal.Helper) *cobra.Command { awsRoleArn = cmd.Flag(flag.AwsRoleArn).Value.String() dataFormat = cmd.Flag(flag.DataFormat).Value.String() if !util.ElemInSlice(opts.SupportedDataFormats(), dataFormat) { - return fmt.Errorf("data format %s is not supported, please use one of %v", dataFormat, opts.SupportedDataFormats()) + return fmt.Errorf("data format %s is not supported, please use one of %q", dataFormat, opts.SupportedDataFormats()) } sourceUrl = cmd.Flag(flag.SourceUrl).Value.String() @@ -248,7 +248,7 @@ func S3Cmd(h *internal.Helper) *cobra.Command { s3Cmd.Flags().StringP(flag.ProjectID, flag.ProjectIDShort, "", "Project ID") s3Cmd.Flags().StringP(flag.ClusterID, flag.ClusterIDShort, "", "Cluster ID") s3Cmd.Flags().String(flag.AwsRoleArn, "", "AWS S3 IAM Role ARN") - s3Cmd.Flags().String(flag.DataFormat, "", fmt.Sprintf("Data format, one of %v", opts.SupportedDataFormats())) + s3Cmd.Flags().String(flag.DataFormat, "", fmt.Sprintf("Data format, one of %q", opts.SupportedDataFormats())) s3Cmd.Flags().String(flag.SourceUrl, "", "The S3 path where the source data file is stored") return s3Cmd } diff --git a/internal/cli/dataimport/start/s3_test.go b/internal/cli/dataimport/start/s3_test.go index 4d45a4bd..ce474edf 100644 --- a/internal/cli/dataimport/start/s3_test.go +++ b/internal/cli/dataimport/start/s3_test.go @@ -106,7 +106,7 @@ func (suite *S3ImportSuite) TestS3ImportArgs() { { name: "start import with unsupported data format", args: []string{"--project-id", projectID, "--cluster-id", clusterID, "--aws-role-arn", awsRoleArn, "--data-format", "yaml", "--source-url", sourceUrl}, - err: fmt.Errorf("data format yaml is not supported, please use one of [CSV SqlFile Parquet AuroraSnapshot]"), + err: fmt.Errorf("data format yaml is not supported, please use one of [\"CSV\" \"SqlFile\" \"Parquet\" \"AuroraSnapshot\"]"), }, { name: "start import with shorthand flag", diff --git a/internal/cli/project/list.go b/internal/cli/project/list.go index f6f646eb..90f8955a 100644 --- a/internal/cli/project/list.go +++ b/internal/cli/project/list.go @@ -96,6 +96,6 @@ func ListCmd(h *internal.Helper) *cobra.Command { }, } - listCmd.Flags().StringP(flag.Output, flag.OutputShort, output.HumanFormat, "Output format. One of: json|human. 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.") return listCmd }