diff --git a/cmd/argo/commands/root.go b/cmd/argo/commands/root.go index f9964b1fae4b..f3729d447d84 100644 --- a/cmd/argo/commands/root.go +++ b/cmd/argo/commands/root.go @@ -137,6 +137,14 @@ If your server is behind an ingress with a path (running "argo server --base-hre cli.SetLogLevel(logLevel) cmdutil.SetGLogLevel(glogLevel) log.WithField("version", argo.GetVersion()).Debug("CLI version") + + // Disable printing of usage string on errors, except for argument validation errors + // (i.e. when the "Args" function returns an error). + // + // This is set here instead of directly in "command" because Cobra + // executes PersistentPreRun after performing argument validation: + // https://github.com/spf13/cobra/blob/3a5efaede9d389703a792e2f7bfe3a64bc82ced9/command.go#L939-L957 + cmd.SilenceUsage = true } command.PersistentFlags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error") command.PersistentFlags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level") diff --git a/test/e2e/cli_test.go b/test/e2e/cli_test.go index 067a85af4d14..bfe327950138 100644 --- a/test/e2e/cli_test.go +++ b/test/e2e/cli_test.go @@ -757,6 +757,7 @@ func (s *CLISuite) TestWorkflowLint() { RunCli([]string{"lint", "--kinds", "wf", "testdata/workflow-template-nested-template.yaml"}, func(t *testing.T, output string, err error) { require.Error(t, err) assert.Contains(t, output, "found nothing to lint in the specified paths, failing...") + assert.NotContains(t, output, "Usage:") }) }) s.Run("All Kinds", func() { @@ -1095,6 +1096,7 @@ func (s *CLISuite) TestTemplateCommands() { s.Run("LintWithoutArgs", func() { s.Given().RunCli([]string{"template", "lint"}, func(t *testing.T, output string, err error) { require.Error(t, err) + assert.Contains(t, output, "Error: requires at least 1 arg(s), only received 0") assert.Contains(t, output, "Usage:") }) })