From 8b5441a687675af5db84d4b1043fe6313591a756 Mon Sep 17 00:00:00 2001 From: Quanzheng Long Date: Fri, 28 May 2021 17:10:48 -0700 Subject: [PATCH 1/2] Change domain data CLI parameter for consistency --- CHANGELOG.md | 4 +++- tools/cli/app.go | 2 +- tools/cli/domain.go | 17 ----------------- tools/cli/domainCommands.go | 24 +++++++++--------------- tools/cli/domainUtils.go | 7 +++++-- 5 files changed, 18 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cb8456b932..a315954e7d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,9 @@ You can find a list of previous releases on the [github releases](https://github - This change contains breaking change on user config. The masterClusterName config key is deprecated and is replaced with primaryClusterName key. (#4185) ### Changed -- Bump CLI version to v0.18.3 (#3959) +- Bump CLI version to v0.19.0 +- Change `--connect-attributes` in `cadence-sql-tool` from URL encoding to the format of k1=v1,k2=v2... +- Change `--domain_data` in `cadence domain update/register` from the format of k1:v1,k2:v2... to the format of k1=v1,k2=v2... ## [0.18.0] - 2021-01-22 diff --git a/tools/cli/app.go b/tools/cli/app.go index dc951c9bf5a..c7fcab4c60c 100644 --- a/tools/cli/app.go +++ b/tools/cli/app.go @@ -27,7 +27,7 @@ import ( const ( // Version is the controlled version string. It should be updated every time // before we release a new version. - Version = "0.18.4" + Version = "0.19.0" ) // SetFactory is used to set the ClientFactory global diff --git a/tools/cli/domain.go b/tools/cli/domain.go index a20a63d30d3..757c4ccc9f9 100644 --- a/tools/cli/domain.go +++ b/tools/cli/domain.go @@ -22,7 +22,6 @@ package cli import ( "fmt" - "strings" "github.com/urfave/cli" ) @@ -46,22 +45,6 @@ func checkRequiredDomainDataKVs(domainData map[string]string) error { return nil } -func parseDomainDataKVs(domainDataStr string) (map[string]string, error) { - kvstrs := strings.Split(domainDataStr, ",") - kvMap := map[string]string{} - for _, kvstr := range kvstrs { - kv := strings.Split(kvstr, ":") - if len(kv) != 2 { - return kvMap, fmt.Errorf("domain data format error. It must be k1:v2,k2:v2,...,kn:vn") - } - k := strings.TrimSpace(kv[0]) - v := strings.TrimSpace(kv[1]) - kvMap[k] = v - } - - return kvMap, nil -} - func newDomainCommands() []cli.Command { return []cli.Command{ { diff --git a/tools/cli/domainCommands.go b/tools/cli/domainCommands.go index 15fd5548cd9..f50ed9d86ec 100644 --- a/tools/cli/domainCommands.go +++ b/tools/cli/domainCommands.go @@ -30,6 +30,8 @@ import ( "strings" "time" + "github.com/uber/cadence/tools/common/flag" + "github.com/olekukonko/tablewriter" "github.com/urfave/cli" @@ -94,16 +96,12 @@ func (d *domainCLIImpl) RegisterDomain(c *cli.Context) { } } - domainData := map[string]string{} + var domainData *flag.StringMap if c.IsSet(FlagDomainData) { - domainDataStr := getRequiredOption(c, FlagDomainData) - domainData, err = parseDomainDataKVs(domainDataStr) - if err != nil { - ErrorAndExit(fmt.Sprintf("Option %s format is invalid.", FlagDomainData), err) - } + domainData = c.Generic(FlagDomainData).(*flag.StringMap) } if len(requiredDomainDataKeys) > 0 { - err = checkRequiredDomainDataKVs(domainData) + err = checkRequiredDomainDataKVs(domainData.Value()) if err != nil { ErrorAndExit("Domain data missed required data.", err) } @@ -131,7 +129,7 @@ func (d *domainCLIImpl) RegisterDomain(c *cli.Context) { Name: domainName, Description: description, OwnerEmail: ownerEmail, - Data: domainData, + Data: domainData.Value(), WorkflowExecutionRetentionPeriodInDays: int32(retentionDays), Clusters: clusters, ActiveClusterName: activeClusterName, @@ -205,13 +203,9 @@ func (d *domainCLIImpl) UpdateDomain(c *cli.Context) { if c.IsSet(FlagOwnerEmail) { ownerEmail = c.String(FlagOwnerEmail) } - domainData := map[string]string{} + var domainData *flag.StringMap if c.IsSet(FlagDomainData) { - domainDataStr := c.String(FlagDomainData) - domainData, err = parseDomainDataKVs(domainDataStr) - if err != nil { - ErrorAndExit("Domain data format is invalid.", err) - } + domainData = c.Generic(FlagDomainData).(*flag.StringMap) } if c.IsSet(FlagRetentionDays) { retentionDays = int32(c.Int(FlagRetentionDays)) @@ -255,7 +249,7 @@ func (d *domainCLIImpl) UpdateDomain(c *cli.Context) { Name: domainName, Description: common.StringPtr(description), OwnerEmail: common.StringPtr(ownerEmail), - Data: domainData, + Data: domainData.Value(), WorkflowExecutionRetentionPeriodInDays: common.Int32Ptr(retentionDays), EmitMetric: common.BoolPtr(emitMetric), HistoryArchivalStatus: archivalStatus(c, FlagHistoryArchivalStatus), diff --git a/tools/cli/domainUtils.go b/tools/cli/domainUtils.go index 28692ca9e25..ed7d058101f 100644 --- a/tools/cli/domainUtils.go +++ b/tools/cli/domainUtils.go @@ -23,6 +23,8 @@ package cli import ( "strings" + "github.com/uber/cadence/tools/common/flag" + "github.com/stretchr/testify/mock" "github.com/uber-go/tally" "github.com/urfave/cli" @@ -127,9 +129,10 @@ var ( Name: FlagClustersWithAlias, Usage: "Clusters", }, - cli.StringFlag{ + cli.GenericFlag{ Name: FlagDomainDataWithAlias, - Usage: "Domain data of key value pairs, in format of k1:v1,k2:v2,k3:v3 ", + Usage: "Domain data of key value pairs (must be in key1=value1,key2=value2,...,keyN=valueN format, e.g. cluster=dca or cluster=dca,instance=cadence)", + Value: &flag.StringMap{}, }, cli.StringFlag{ Name: FlagSecurityTokenWithAlias, From 0e9ab78155f517a40bad8b26a3613ed957f6716f Mon Sep 17 00:00:00 2001 From: Quanzheng Long Date: Fri, 28 May 2021 17:17:49 -0700 Subject: [PATCH 2/2] fix --- tools/cli/domainUtils.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/cli/domainUtils.go b/tools/cli/domainUtils.go index ed7d058101f..f161b145e92 100644 --- a/tools/cli/domainUtils.go +++ b/tools/cli/domainUtils.go @@ -79,9 +79,10 @@ var ( Name: FlagIsGlobalDomainWithAlias, Usage: "Flag to indicate whether domain is a global domain", }, - cli.StringFlag{ + cli.GenericFlag{ Name: FlagDomainDataWithAlias, - Usage: "Domain data of key value pairs, in format of k1:v1,k2:v2,k3:v3", + Usage: "Domain data of key value pairs (must be in key1=value1,key2=value2,...,keyN=valueN format, e.g. cluster=dca or cluster=dca,instance=cadence)", + Value: &flag.StringMap{}, }, cli.StringFlag{ Name: FlagSecurityTokenWithAlias,