From 55d94bd02f7b1253a50e445586e8aa14e4ede125 Mon Sep 17 00:00:00 2001 From: yougg Date: Mon, 17 Oct 2022 20:46:50 +0800 Subject: [PATCH] customize slice flag value separator --- kit/cmd/go.mod | 7 ++++--- kit/cmd/go.sum | 12 ++++++------ kit/cmd/tcmqcli.go | 23 ++++++++++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/kit/cmd/go.mod b/kit/cmd/go.mod index a4ea8dd..beedb80 100644 --- a/kit/cmd/go.mod +++ b/kit/cmd/go.mod @@ -4,13 +4,14 @@ go 1.19 require ( github.com/integrii/flaggy v1.5.2 - github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.498 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.514 github.com/yougg/cmq-go-tdmq v0.0.0-00010101000000-000000000000 ) -require github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.498 +require github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.514 replace ( - github.com/integrii/flaggy => github.com/yougg/flaggy v0.0.0-20220916091504-e64624f2dc64 + github.com/integrii/flaggy => github.com/yougg/flaggy v0.0.0-20220927023241-44a00f282fe3 github.com/yougg/cmq-go-tdmq => ../.. +//github.com/yougg/cmq-go-tdmq/tcp => ../../tcp ) diff --git a/kit/cmd/go.sum b/kit/cmd/go.sum index 722955f..fd11c4e 100644 --- a/kit/cmd/go.sum +++ b/kit/cmd/go.sum @@ -1,9 +1,9 @@ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.498 h1:0OVa3ONUD47gpROisKXl90x9vGH4yt8mtQCoF3vW1fg= -github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.498/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= -github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.498 h1:zyGTFRSTUPVtbiTnc/oly6bi11ucgr0PCzESSYzF3BM= -github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.498/go.mod h1:c8C3tygNKoXpymwRr/q5kxjsIYC7rwXOB6ClOkFlKoA= -github.com/yougg/flaggy v0.0.0-20220916091504-e64624f2dc64 h1:dT2AOGO/o5kFj6wbEcGOYpDga+NcgqMikCw/T5c8Ayw= -github.com/yougg/flaggy v0.0.0-20220916091504-e64624f2dc64/go.mod h1:dO13u7SYuhk910nayCJ+s1DeAAGC1THCMj1uSFmwtQ8= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.514 h1:CgYPKvnfjxs3dQPcM/nUqIk+ZIZAV6+hBvEpsPP7OSk= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.514/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.514 h1:m5x+SDLJsu2F6Y78kK5qB5xPnaTx1L29yC4NP/mJAys= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.514/go.mod h1:X1jcrUrL6yVnGVeDtnoXy9A8Tc285CxPl6t63xxCR+0= +github.com/yougg/flaggy v0.0.0-20220927023241-44a00f282fe3 h1:O0wHnahujvKnJHbmn+3hKnMM0FiyaYA+ae8U/nv5AAg= +github.com/yougg/flaggy v0.0.0-20220927023241-44a00f282fe3/go.mod h1:dO13u7SYuhk910nayCJ+s1DeAAGC1THCMj1uSFmwtQ8= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/kit/cmd/tcmqcli.go b/kit/cmd/tcmqcli.go index e760262..aac3e38 100644 --- a/kit/cmd/tcmqcli.go +++ b/kit/cmd/tcmqcli.go @@ -140,6 +140,11 @@ var ( filter = `queue` ) +// set VALUE_SEPARATOR=... environment variable for value separator +// the default slice flag parameters value separator is ',' +// customize the VALUE_SEPARATOR to avoid the slice value be separate by ',' +var valueSeparator string + var ( client *tcmq.Client mgrClient *v20200217.Client @@ -267,7 +272,10 @@ var ( ) func init() { - flaggy.SetVersion(`v0.1.3`) + if separator := os.Getenv(`VALUE_SEPARATOR`); separator != `` { + valueSeparator = separator + } + flaggy.SetVersion(`v0.2.1`) flaggy.SetDescription(`TDMQ-CMQ command line tool`) flagFn := func(subCmd *flaggy.Subcommand, flags []Flag) { for _, f := range flags { @@ -304,23 +312,24 @@ func init() { f.Value = make([]string, 0) } v = f.Value.([]string) - subCmd.StringSlice(&v, f.Name, f.FullName, f.Usage) + subCmd.StringSlice(&v, f.Name, f.FullName, f.Usage, valueSeparator) case *[]string: if isNilValue { f.Value = &[]string{} } v = f.Value.(*[]string) - subCmd.StringSlice(v, f.Name, f.FullName, f.Usage) + subCmd.StringSlice(v, f.Name, f.FullName, f.Usage, valueSeparator) case []*string: if isNilValue { f.Value = make([]*string, 0) } v = f.Value.([]*string) subCmd.Flags = append(subCmd.Flags, &flaggy.Flag{ - AssignmentVar: &v, - ShortName: f.Name, - LongName: f.FullName, - Description: f.Usage, + AssignmentVar: &v, + ShortName: f.Name, + LongName: f.FullName, + Description: f.Usage, + ValueSeparator: valueSeparator, }) default: log.Printf("invalid flag type: %#v", f)