Skip to content

Commit

Permalink
customize slice flag value separator
Browse files Browse the repository at this point in the history
  • Loading branch information
yougg committed Oct 17, 2022
1 parent 859cebe commit 55d94bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
7 changes: 4 additions & 3 deletions kit/cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
12 changes: 6 additions & 6 deletions kit/cmd/go.sum
Original file line number Diff line number Diff line change
@@ -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=
23 changes: 16 additions & 7 deletions kit/cmd/tcmqcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 55d94bd

Please sign in to comment.