From b1ad8d150a2a9c6ba12f7007174707828ce5942e Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Wed, 30 Mar 2022 15:50:55 +0200 Subject: Make zone flag global --- client/go/cmd/config_test.go | 2 +- client/go/cmd/deploy.go | 6 ++---- client/go/cmd/prod.go | 2 +- client/go/cmd/root.go | 8 +++++--- client/go/cmd/test.go | 10 ++++------ 5 files changed, 13 insertions(+), 15 deletions(-) (limited to 'client') diff --git a/client/go/cmd/config_test.go b/client/go/cmd/config_test.go index 9f695429e99..0d47d170845 100644 --- a/client/go/cmd/config_test.go +++ b/client/go/cmd/config_test.go @@ -31,7 +31,7 @@ func TestConfig(t *testing.T) { assertConfigCommand(t, "", "config", "set", "application", "t1.a1.i1") assertConfigCommand(t, "application = t1.a1.i1\n", "config", "get", "application") - assertConfigCommand(t, "api-key-file = /tmp/private.key\napplication = t1.a1.i1\ncolor = auto\ninstance = \nquiet = false\ntarget = https://127.0.0.1\nwait = 0\n", "config", "get") + assertConfigCommand(t, "api-key-file = /tmp/private.key\napplication = t1.a1.i1\ncolor = auto\ninstance = \nquiet = false\ntarget = https://127.0.0.1\nwait = 0\nzone = \n", "config", "get") assertConfigCommand(t, "", "config", "set", "wait", "60") assertConfigCommandErr(t, "Error: wait option must be an integer >= 0, got \"foo\"\n", "config", "set", "wait", "foo") diff --git a/client/go/cmd/deploy.go b/client/go/cmd/deploy.go index ffd4ab26891..7e8f98d0abc 100644 --- a/client/go/cmd/deploy.go +++ b/client/go/cmd/deploy.go @@ -17,7 +17,6 @@ import ( func newDeployCmd(cli *CLI) *cobra.Command { var ( - zoneArg string logLevelArg string ) cmd := &cobra.Command{ @@ -46,7 +45,7 @@ $ vespa deploy -t cloud -z perf.aws-us-east-1c`, if err != nil { return err } - target, err := cli.target(targetOptions{zone: zoneArg, logLevel: logLevelArg}) + target, err := cli.target(targetOptions{logLevel: logLevelArg}) if err != nil { return err } @@ -79,8 +78,7 @@ $ vespa deploy -t cloud -z perf.aws-us-east-1c`, return waitForQueryService(cli, result.ID) }, } - cmd.PersistentFlags().StringVarP(&zoneArg, "zone", "z", "", "The zone to use for deployment. This defaults to a dev zone") - cmd.PersistentFlags().StringVarP(&logLevelArg, "log-level", "l", "error", `Log level for Vespa logs. Must be "error", "warning", "info" or "debug"`) + cmd.Flags().StringVarP(&logLevelArg, "log-level", "l", "error", `Log level for Vespa logs. Must be "error", "warning", "info" or "debug"`) return cmd } diff --git a/client/go/cmd/prod.go b/client/go/cmd/prod.go index 2654bcb396b..5bc4851dfa7 100644 --- a/client/go/cmd/prod.go +++ b/client/go/cmd/prod.go @@ -406,6 +406,6 @@ func verifyTest(cli *CLI, testsParent string, suite string, required bool) error } return nil } - _, _, err = runTests(cli, "", testDirectory, true) + _, _, err = runTests(cli, testDirectory, true) return err } diff --git a/client/go/cmd/root.go b/client/go/cmd/root.go index 5fc756db037..387c72a1f17 100644 --- a/client/go/cmd/root.go +++ b/client/go/cmd/root.go @@ -28,6 +28,7 @@ import ( const ( applicationFlag = "application" instanceFlag = "instance" + zoneFlag = "zone" targetFlag = "target" waitFlag = "wait" colorFlag = "color" @@ -60,6 +61,7 @@ type Flags struct { target string application string instance string + zone string waitSecs int color string quiet bool @@ -76,8 +78,6 @@ type ErrCLI struct { } type targetOptions struct { - // zone declares the zone use when using this target. If empty, a default zone for the system is chosen. - zone string // logLevel sets the log level to use for this target. If empty, it defaults to "info". logLevel string // noCertificate declares that no client certificate should be required when using this target. @@ -154,6 +154,7 @@ func (c *CLI) loadConfig() error { bindings.bindFlag(targetFlag, c.cmd) bindings.bindFlag(applicationFlag, c.cmd) bindings.bindFlag(instanceFlag, c.cmd) + bindings.bindFlag(zoneFlag, c.cmd) bindings.bindFlag(waitFlag, c.cmd) bindings.bindFlag(colorFlag, c.cmd) bindings.bindFlag(quietFlag, c.cmd) @@ -201,6 +202,7 @@ func (c *CLI) configureFlags() { c.cmd.PersistentFlags().StringVarP(&flags.target, targetFlag, "t", "local", "The name or URL of the recipient of this command") c.cmd.PersistentFlags().StringVarP(&flags.application, applicationFlag, "a", "", "The application to manage") c.cmd.PersistentFlags().StringVarP(&flags.instance, instanceFlag, "i", "", "The instance of the application to manage") + c.cmd.PersistentFlags().StringVarP(&flags.zone, zoneFlag, "z", "", "The zone to use. This defaults to a dev zone") c.cmd.PersistentFlags().IntVarP(&flags.waitSecs, waitFlag, "w", 0, "Number of seconds to wait for a service to become ready") c.cmd.PersistentFlags().StringVarP(&flags.color, colorFlag, "c", "auto", "Whether to use colors in output.") c.cmd.PersistentFlags().BoolVarP(&flags.quiet, quietFlag, "q", false, "Quiet mode. Only errors will be printed") @@ -318,7 +320,7 @@ func (c *CLI) createCloudTarget(targetType string, opts targetOptions) (vespa.Ta if err != nil { return nil, err } - deployment, err := c.config.deploymentIn(opts.zone, system) + deployment, err := c.config.deploymentIn(c.flags.zone, system) if err != nil { return nil, err } diff --git a/client/go/cmd/test.go b/client/go/cmd/test.go index 28879982b17..acb6231623e 100644 --- a/client/go/cmd/test.go +++ b/client/go/cmd/test.go @@ -26,7 +26,6 @@ import ( ) func newTestCmd(cli *CLI) *cobra.Command { - var zoneArg string testCmd := &cobra.Command{ Use: "test test-directory-or-file", Short: "Run a test suite, or a single test", @@ -41,7 +40,7 @@ $ vespa test src/test/application/tests/system-test/feed-and-query.json`, DisableAutoGenTag: true, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - count, failed, err := runTests(cli, zoneArg, args[0], false) + count, failed, err := runTests(cli, args[0], false) if err != nil { return err } @@ -65,11 +64,10 @@ $ vespa test src/test/application/tests/system-test/feed-and-query.json`, } }, } - testCmd.PersistentFlags().StringVarP(&zoneArg, "zone", "z", "", "The zone to use for deployment. This defaults to a dev zone") return testCmd } -func runTests(cli *CLI, zone, rootPath string, dryRun bool) (int, []string, error) { +func runTests(cli *CLI, rootPath string, dryRun bool) (int, []string, error) { count := 0 failed := make([]string, 0) if stat, err := os.Stat(rootPath); err != nil { @@ -79,7 +77,7 @@ func runTests(cli *CLI, zone, rootPath string, dryRun bool) (int, []string, erro if err != nil { return 0, nil, errHint(err, "See https://docs.vespa.ai/en/reference/testing") } - context := testContext{testsPath: rootPath, dryRun: dryRun, cli: cli, zone: zone} + context := testContext{testsPath: rootPath, dryRun: dryRun, cli: cli, zone: cli.flags.zone} previousFailed := false for _, test := range tests { if !test.IsDir() && filepath.Ext(test.Name()) == ".json" { @@ -479,7 +477,7 @@ type testContext struct { func (t *testContext) target() (vespa.Target, error) { if t.lazyTarget == nil { - target, err := t.cli.target(targetOptions{zone: t.zone}) + target, err := t.cli.target(targetOptions{}) if err != nil { return nil, err } -- cgit v1.2.3