Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't print help for non-validation errors. Fixes #13826 #13831

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/argo/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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:")
})
})
Expand Down
Loading