From 3d13f777ec79749091621128f031ccb6c6dff5f9 Mon Sep 17 00:00:00 2001 From: feedmeapples Date: Thu, 29 Sep 2022 01:58:36 -0400 Subject: [PATCH] Ensure urfave/cli accepts flag values with comma --- Makefile | 3 +- go.mod | 3 +- go.sum | 7 ++-- tools/tdbg/app.go | 1 - tools/tdbg/app_test.go | 75 +++++++++++++++++++++++++++++++++++++++++ tools/tdbg/util_test.go | 19 ----------- 6 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 tools/tdbg/app_test.go diff --git a/Makefile b/Makefile index d4ed2b8bd36..f915017c7b0 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,8 @@ INTEG_TEST_DIRS := $(filter $(INTEG_TEST_ROOT)/ $(INTEG_TEST_NDC_ROOT)/,$(TEST_D UNIT_TEST_DIRS := $(filter-out $(INTEG_TEST_ROOT)% $(INTEG_TEST_XDC_ROOT)% $(INTEG_TEST_NDC_ROOT)%,$(TEST_DIRS)) PINNED_DEPENDENCIES := \ - github.com/go-sql-driver/mysql@v1.5.0 + github.com/go-sql-driver/mysql@v1.5.0 \ + github.com/urfave/cli/v2@v2.4.0 # needs to accept comma in values before unlocking https://github.com/urfave/cli/pull/1241 # Code coverage output files. COVER_ROOT := ./.coverage diff --git a/go.mod b/go.mod index 4c28beba6e9..513c6407bce 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/temporalio/tctl-kit v0.0.0-20220902020621-bce71d13b67c github.com/uber-go/tally/v4 v4.1.2 github.com/urfave/cli v1.22.10 - github.com/urfave/cli/v2 v2.16.3 + github.com/urfave/cli/v2 v2.4.0 github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0 go.opentelemetry.io/otel v1.10.0 @@ -111,7 +111,6 @@ require ( github.com/twmb/murmur3 v1.1.6 // indirect github.com/uber-common/bark v1.3.0 // indirect github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.opencensus.io v0.23.0 // indirect go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.31.0 // indirect diff --git a/go.sum b/go.sum index 495b5a2889e..0f91f268023 100644 --- a/go.sum +++ b/go.sum @@ -124,6 +124,7 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -463,10 +464,8 @@ github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVK github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk= github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/urfave/cli/v2 v2.16.3 h1:gHoFIwpPjoyIMbJp/VFd+/vuD0dAgFK4B6DpEMFJfQk= -github.com/urfave/cli/v2 v2.16.3/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/urfave/cli/v2 v2.4.0 h1:m2pxjjDFgDxSPtO8WSdbndj17Wu2y8vOT86wE/tjr+I= +github.com/urfave/cli/v2 v2.4.0/go.mod h1:NX9W0zmTvedE5oDoOMs2RTC8RvdK98NTYZE5LbaEYPg= github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ= github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/tools/tdbg/app.go b/tools/tdbg/app.go index 4d476217d68..213c2ea160a 100644 --- a/tools/tdbg/app.go +++ b/tools/tdbg/app.go @@ -46,7 +46,6 @@ func NewCliApp() *cli.App { app.Name = "tdbg" app.Usage = "A command-line tool for Temporal server debugging" app.Version = headers.ServerVersion - app.Suggest = true app.Flags = []cli.Flag{ &cli.StringFlag{ Name: FlagAddress, diff --git a/tools/tdbg/app_test.go b/tools/tdbg/app_test.go new file mode 100644 index 00000000000..aa350c54904 --- /dev/null +++ b/tools/tdbg/app_test.go @@ -0,0 +1,75 @@ +// The MIT License +// +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. +// +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package tdbg + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + "github.com/urfave/cli/v2" +) + +func (s *utilSuite) SetupTest() { + s.Assertions = require.New(s.T()) +} +func TestUtilSuite(t *testing.T) { + suite.Run(t, new(utilSuite)) +} + +type utilSuite struct { + *require.Assertions + suite.Suite +} + +// TestAcceptStringSliceArgsWithCommas tests that the cli accepts string slice args with commas +// If the test fails consider downgrading urfave/cli/v2 to v2.4.0 +// See https://github.com/urfave/cli/pull/1241 +func (s *utilSuite) TestAcceptStringSliceArgsWithCommas() { + app := cli.NewApp() + app.Name = "testapp" + app.Commands = []*cli.Command{ + { + Name: "dostuff", + Action: func(c *cli.Context) error { + s.Equal(2, len(c.StringSlice("input"))) + for _, inp := range c.StringSlice("input") { + var thing any + s.NoError(json.Unmarshal([]byte(inp), &thing)) + } + return nil + }, + Flags: []cli.Flag{ + &cli.StringSliceFlag{ + Name: "input", + }, + }, + }, + } + app.Run([]string{"testapp", "dostuff", + "--input", `{"field1": 34, "field2": false}`, + "--input", `{"numbers": [4,5,6]}`}) +} diff --git a/tools/tdbg/util_test.go b/tools/tdbg/util_test.go index 33500d55bac..f5a73816610 100644 --- a/tools/tdbg/util_test.go +++ b/tools/tdbg/util_test.go @@ -24,25 +24,6 @@ package tdbg -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" -) - -func (s *utilSuite) SetupTest() { - s.Assertions = require.New(s.T()) -} -func TestUtilSuite(t *testing.T) { - suite.Run(t, new(utilSuite)) -} - -type utilSuite struct { - *require.Assertions - suite.Suite -} - func (s *utilSuite) TestStringToEnum_MapCaseInsensitive() { enumValues := map[string]int32{ "Unspecified": 0,