Skip to content

fix: document required flags in examples and clean up error output#911

Open
clcollins wants to merge 6 commits into
openshift:masterfrom
clcollins:worktree-snappy-jingling-elephant
Open

fix: document required flags in examples and clean up error output#911
clcollins wants to merge 6 commits into
openshift:masterfrom
clcollins:worktree-snappy-jingling-elephant

Conversation

@clcollins

@clcollins clcollins commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Suppress usage dump on errors: Added SilenceUsage in PersistentPreRun so missing-flag and RunE errors show only the error + a help hint, not a wall of usage text. Unknown commands/flags still show usage.
  • Fix double error printing: Changed main.go to use ExecuteC() and replaced the redundant error print with Run '<command> --help' for usage.
  • Add Example fields: Added or fixed Example fields on 37 commands that had required flags (e.g. --reason, --cluster-id) but no examples, or had examples that omitted required flags.
  • Standardize placeholders: Replaced hard-coded ticket numbers (OHSS-1234, SREP-3811, OSD-XYZ) and angle-bracket placeholders (<cluster-id>) with ${VARIABLE} style across all examples.
  • Regression test: New TestRequiredFlagsDocumentedInExamples walks the entire command tree and validates every MarkFlagRequired flag appears in its command's Example field.

Before / After

# Before — error buried in usage dump, printed twice:
Error: required flag(s) "justification", "ohss", "reason" not set
Usage: osdctl cluster resize infra [flags]
... 30 lines of flags and help ...
required flag(s) "justification", "ohss", "reason" not set

# After — clean error with help hint:
Error: required flag(s) "justification", "ohss", "reason" not set
Run 'osdctl cluster resize infra --help' for usage.

Secondary Lint Fixes

Pre-existing lint issues fixed to get make lint passing clean:

  • cmd/evidence/collect.go: replaced WriteString(fmt.Sprintf(...)) with fmt.Fprintf(...) (staticcheck QF1012, 15 instances)
  • cmd/account/cli.go: suppressed gosec G117 false positive on intentional credential output
  • cmd/promote/rhobs/rhobs.go: suppressed gosec G703 false positive on hardcoded path candidates (2 instances)
  • pkg/utils/ocm_test.go: suppressed gosec G117 false positive on test fixtures with fake credentials (3 instances)

Test plan

  • go build ./... compiles
  • go test ./cmd/... — all existing tests pass
  • make lint — 0 issues
  • make verify-docs — docs regenerated and up to date
  • New TestRequiredFlagsDocumentedInExamples passes
  • Manual: run a command without a required flag — confirm clean error output
  • Manual: run a command with --help — confirm full help text still appears
  • Manual: run a command with an unknown flag — confirm usage still appears

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Updated CLI help and many docs with consistent placeholders, corrected wording/typos, and expanded Examples for numerous commands.
  • Tests

    • Added a test to ensure required flags are documented in command examples.
  • Improvements

    • Improved command error/help output behavior and refined evidence-collection summary formatting for clearer CLI feedback.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR standardizes CLI help text to ${PLACEHOLDER} syntax, adds or improves Examples across many commands and docs, refactors evidence summary formatting, removes selective Cobra error-silencing flags, changes root/main error handling to use ExecuteC(), adds a test ensuring required flags appear in Examples, and adds targeted gosec suppressions.

Changes

CLI Help and Error Handling Improvements

Layer / File(s) Summary
Help text and examples (commands)
cmd/...
Many Cobra Use/Long/Example strings updated to ${...} placeholders and expanded/rewritten examples across numerous command files.
Documentation examples
docs/...
Docs updated to match command examples and placeholders, plus some synopsis/typo fixes and trimmed example blocks.
Required flags test
cmd/required_flags_test.go
Added TestRequiredFlagsDocumentedInExamples to verify commands list required flags in their Example text.
Evidence collect formatting
cmd/evidence/collect.go
Refactored saveSummary() to use fmt.Fprintf(&sb, ...) for summary output and updated example placeholders in evidence help/comment.
Root/main error handling
cmd/cmd.go, main.go
Set cmd.SilenceUsage = true in root PersistentPreRun; switched to ExecuteC() and conditional error/usage hint printing.
Gosec suppressions
cmd/*, pkg/*
Added //nolint:gosec comments on deliberate credential/file operations in code and tests.
SilenceErrors removal
cmd/org/*, cmd/rhobs/*, cmd/upgrade.go
Removed SilenceErrors: true from many Cobra command initializers, altering whether Cobra suppresses error output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • devppratik
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci

openshift-ci Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: clcollins

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/alerts/list_alerts.go`:
- Around line 27-29: The example help text in cmd/alerts/list_alerts.go says
"firing alerts" but omits the --level flag; update the example command in the
command's help/Example string (the alerts list usage text) to include --level
firing (i.e., `osdctl alerts list --cluster-id ${CLUSTER_ID} --level firing
--reason "${REASON}"`) so the example matches the description.

In `@cmd/alerts/silence/add_silence.go`:
- Line 31: The command help text in the Long field contains a typo ("specfic")
and is awkwardly phrased; update the Long string (the Cobra command's Long
description) to correct the spelling to "specific" and improve readability, e.g.
"Add a new silence for a specific alert or for all alerts, including a comment
and duration." Replace the existing Long value with this clearer sentence in
add_silence.go.

In `@cmd/alerts/silence/clear_silence.go`:
- Line 27: The command's Long description (the Long field in clear_silence.go)
is unclear and has a typo "silenceid"; update it to a clear, user-facing
sentence such as "Expire all silences, or expire a specific silence by its
silence ID." Locate the Long string in clear_silence.go (the Long field of the
command definition) and replace the existing text with the improved phrasing.

In `@cmd/alerts/silence/silence_org.go`:
- Line 26: Update the user-facing help text in the org silence command's Long
description (the Long field in the command definition in silence_org.go) to fix
the typo "specfic" → "specific" and rephrase to "add a new silence for specific
alerts or all alerts with a comment and duration for an organization. OHSS
required for org-wide silence" so the sentence reads clearly and grammatically
correct.

In `@cmd/cluster/etcd_replace.go`:
- Line 46: Update the help text string that currently reads "Replaces an
unhealthy ectd node using the member id provided" to correct the typo "ectd" →
"etcd" (the Long field in the etcd replace command definition in
cmd/cluster/etcd_replace.go). Locate the Cobra command's Long description (the
string literal shown in the diff) and replace the misspelled word so the help
output matches the command name and examples.

In `@cmd/cluster/resize/infra_node.go`:
- Around line 75-78: Update the example invocations that pass the --ohss flag to
use the correct OHSS placeholder instead of the REASON placeholder: replace the
occurrences of "${REASON}" bound to --ohss with a dedicated "${OHSS}"
placeholder in the example command strings so --ohss reflects an OHSS ticket
(change both examples that include --ohss).

In `@main.go`:
- Around line 25-27: When handling the error returned from command.ExecuteC(),
guard against a nil resolved before calling resolved.CommandPath(): change the
error branch in main (where resolved, err := command.ExecuteC() is handled) to
first check if resolved != nil and use resolved.CommandPath(), otherwise print a
safe fallback usage string (e.g., "Run '<command> --help' for usage." or a
generic message) and then exit; ensure the nil-check surrounds any dereference
of resolved so no panic occurs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8a9fc1a7-48b6-4de7-b16e-1c67164821b6

📥 Commits

Reviewing files that changed from the base of the PR and between 486780d and c92d6ac.

📒 Files selected for processing (52)
  • cmd/account/rotate-secret.go
  • cmd/alerts/list_alerts.go
  • cmd/alerts/silence/add_silence.go
  • cmd/alerts/silence/clear_silence.go
  • cmd/alerts/silence/list_silence.go
  • cmd/alerts/silence/silence_org.go
  • cmd/cloudtrail/errors.go
  • cmd/cloudtrail/permission-denied.go
  • cmd/cluster/access/access.go
  • cmd/cluster/access/cleanup.go
  • cmd/cluster/cad/run.go
  • cmd/cluster/changevolumetype.go
  • cmd/cluster/checkbanneduser.go
  • cmd/cluster/context.go
  • cmd/cluster/detachstuckvolume.go
  • cmd/cluster/etcd_health.go
  • cmd/cluster/etcd_replace.go
  • cmd/cluster/getenvvars.go
  • cmd/cluster/health.go
  • cmd/cluster/hypershift_info.go
  • cmd/cluster/loggingcheck.go
  • cmd/cluster/reports/create.go
  • cmd/cluster/reports/get.go
  • cmd/cluster/reports/list.go
  • cmd/cluster/resize/controlplane_node.go
  • cmd/cluster/resize/infra_node.go
  • cmd/cluster/resize/requestserving_node.go
  • cmd/cluster/snapshot.go
  • cmd/cluster/ssh/key.go
  • cmd/cluster/support/delete.go
  • cmd/cluster/support/post.go
  • cmd/cluster/support/status.go
  • cmd/cluster/transferowner.go
  • cmd/cluster/validatepullsecretext.go
  • cmd/cluster/verifydns.go
  • cmd/cmd.go
  • cmd/cost/create.go
  • cmd/cost/list.go
  • cmd/cost/reconcile.go
  • cmd/dynatrace/dashboardCmd.go
  • cmd/dynatrace/urlCmd.go
  • cmd/evidence/collect.go
  • cmd/hcp/backup/backup.go
  • cmd/hcp/get-cp-autoscaling-status/get_cp_autoscaling_status.go
  • cmd/hcp/mustgather/mustGather.go
  • cmd/hcp/status/status.go
  • cmd/iampermissions/diff.go
  • cmd/iampermissions/get.go
  • cmd/iampermissions/save.go
  • cmd/required_flags_test.go
  • cmd/servicelog/list.go
  • main.go

Comment thread cmd/alerts/list_alerts.go Outdated
Comment thread cmd/alerts/silence/add_silence.go Outdated
Comment thread cmd/alerts/silence/clear_silence.go Outdated
Comment thread cmd/alerts/silence/silence_org.go Outdated
Comment thread cmd/cluster/etcd_replace.go Outdated
Comment thread cmd/cluster/resize/infra_node.go Outdated
Comment thread main.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
main.go (1)

27-29: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add fallback usage hint when resolved is nil.

Lines 27-29 avoid the panic, but the nil path exits silently. Please emit a generic help hint in the else branch so users always get guidance.

Suggested patch
 	if err != nil {
 		if resolved != nil {
 			fmt.Fprintf(os.Stderr, "Run '%s --help' for usage.\n", resolved.CommandPath())
+		} else {
+			fmt.Fprintln(os.Stderr, "Run 'osdctl --help' for usage.")
 		}
 		os.Exit(1)
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@main.go` around lines 27 - 29, The current code prints a usage hint only when
resolved != nil; add an else branch to emit a fallback help hint when resolved
is nil so users aren’t left without guidance. Modify the branch around resolved
and CommandPath(): keep the existing fmt.Fprintf(os.Stderr, "Run '%s --help' for
usage.\n", resolved.CommandPath()) for the non-nil case and in the else branch
call fmt.Fprintf(os.Stderr, "Run '<command> --help' for usage.\n") or similar
generic text (or derive the binary name from os.Args[0]) to ensure a helpful
message is always printed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@main.go`:
- Around line 27-29: The current code prints a usage hint only when resolved !=
nil; add an else branch to emit a fallback help hint when resolved is nil so
users aren’t left without guidance. Modify the branch around resolved and
CommandPath(): keep the existing fmt.Fprintf(os.Stderr, "Run '%s --help' for
usage.\n", resolved.CommandPath()) for the non-nil case and in the else branch
call fmt.Fprintf(os.Stderr, "Run '<command> --help' for usage.\n") or similar
generic text (or derive the binary name from os.Args[0]) to ensure a helpful
message is always printed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3019d305-3bf2-4dea-9206-26200709dcd9

📥 Commits

Reviewing files that changed from the base of the PR and between bdf681e and 0ecee4f.

📒 Files selected for processing (18)
  • cmd/account/cli.go
  • cmd/alerts/list_alerts.go
  • cmd/alerts/silence/add_silence.go
  • cmd/alerts/silence/clear_silence.go
  • cmd/alerts/silence/silence_org.go
  • cmd/cluster/etcd_replace.go
  • cmd/cluster/resize/infra_node.go
  • cmd/evidence/collect.go
  • cmd/promote/rhobs/rhobs.go
  • docs/README.md
  • docs/osdctl_alert_list.md
  • docs/osdctl_alert_silence_add.md
  • docs/osdctl_alert_silence_expire.md
  • docs/osdctl_alert_silence_org.md
  • docs/osdctl_cluster_etcd-member-replace.md
  • docs/osdctl_cluster_resize_infra.md
  • main.go
  • pkg/utils/ocm_test.go
✅ Files skipped from review due to trivial changes (8)
  • cmd/promote/rhobs/rhobs.go
  • docs/osdctl_alert_silence_expire.md
  • pkg/utils/ocm_test.go
  • cmd/alerts/silence/clear_silence.go
  • docs/osdctl_alert_silence_add.md
  • cmd/alerts/silence/add_silence.go
  • docs/README.md
  • docs/osdctl_alert_silence_org.md
🚧 Files skipped from review as they are similar to previous changes (8)
  • cmd/alerts/silence/silence_org.go
  • docs/osdctl_cluster_resize_infra.md
  • cmd/alerts/list_alerts.go
  • cmd/cluster/resize/infra_node.go
  • cmd/cluster/etcd_replace.go
  • docs/osdctl_alert_list.md
  • cmd/evidence/collect.go
  • docs/osdctl_cluster_etcd-member-replace.md

@clcollins

Copy link
Copy Markdown
Member Author

/label tide/merge-method-squash

🤖 Claude claude@anthropic.com commenting on behalf of @clcollins

@openshift-ci openshift-ci Bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jun 5, 2026
Comment thread main.go
if err := command.Execute(); err != nil {
_, err := fmt.Fprintf(os.Stderr, "%v\n", err)
if err != nil {
fmt.Println("Error while printing to stderr: ", err.Error())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this print causes an incorrect command to duplicate the error message printed by cobra already, i.e.

$ osdctl test
Error: unknown command "test" for "osdctl"

Did you mean this?
        cost

Run 'osdctl --help' for usage.
Run 'osdctl --help' for usage.
exit status 1

The removal of printing os.Stderr here also means that some commands (seems like mostly the rhobs and org ones) which have a SilenceErrors applied won't print an error message at all;

$ osdctl rhobs metrics "up" -o badformat
Run 'osdctl rhobs metrics --help' for usage.

I guess the cleanest solution would be to bring those commands in-line with the rest of the repo 🙂

@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/rhobs/metricsCmd.go (1)

16-20: 💤 Low value

Consider removing redundant argument validation.

The Args: cobra.ExactArgs(1) validator on line 16 ensures exactly one argument is provided before RunE executes, making the manual len(args) != 1 check on lines 18-20 unreachable. This check can be safely removed.

♻️ Simplify by removing dead code
 	RunE: func(cmd *cobra.Command, args []string) error {
-		if len(args) != 1 {
-			return fmt.Errorf("exactly one Prometheus expression must be provided as an argument")
-		}
-
 		outputFormat, err := GetMetricsFormatFromString(outputFormatStr)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/rhobs/metricsCmd.go` around lines 16 - 20, Remove the redundant runtime
argument check inside the RunE handler: the CLI command already sets Args:
cobra.ExactArgs(1), so the manual conditional that tests len(args) != 1 and
returns an error should be deleted; update the RunE anonymous function (the
handler defined as RunE) to assume a single arg is present and remove the
unreachable len(args) check to simplify the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/rhobs/metricsCmd.go`:
- Around line 16-20: Remove the redundant runtime argument check inside the RunE
handler: the CLI command already sets Args: cobra.ExactArgs(1), so the manual
conditional that tests len(args) != 1 and returns an error should be deleted;
update the RunE anonymous function (the handler defined as RunE) to assume a
single arg is present and remove the unreachable len(args) check to simplify the
code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 20a79d7d-94d9-4426-9d73-2d510f582f02

📥 Commits

Reviewing files that changed from the base of the PR and between 0ecee4f and 4553bb3.

📒 Files selected for processing (41)
  • cmd/account/rotate-secret.go
  • cmd/alerts/list_alerts.go
  • cmd/alerts/silence/add_silence.go
  • cmd/alerts/silence/clear_silence.go
  • cmd/alerts/silence/list_silence.go
  • cmd/alerts/silence/silence_org.go
  • cmd/cluster/access/access.go
  • cmd/cluster/access/cleanup.go
  • cmd/cluster/checkbanneduser.go
  • cmd/cluster/context.go
  • cmd/cluster/detachstuckvolume.go
  • cmd/cluster/etcd_health.go
  • cmd/cluster/etcd_replace.go
  • cmd/cluster/getenvvars.go
  • cmd/cluster/health.go
  • cmd/cluster/loggingcheck.go
  • cmd/cluster/support/delete.go
  • cmd/cluster/support/status.go
  • cmd/cluster/transferowner.go
  • cmd/cluster/verifydns.go
  • cmd/dynatrace/dashboardCmd.go
  • cmd/dynatrace/urlCmd.go
  • cmd/iampermissions/diff.go
  • cmd/iampermissions/get.go
  • cmd/iampermissions/save.go
  • cmd/org/aws-accounts.go
  • cmd/org/clusters.go
  • cmd/org/current.go
  • cmd/org/customers.go
  • cmd/org/describe.go
  • cmd/org/get.go
  • cmd/org/labels.go
  • cmd/org/users.go
  • cmd/rhobs/cellCmd.go
  • cmd/rhobs/logsCmd.go
  • cmd/rhobs/mcpCmd.go
  • cmd/rhobs/metricsCmd.go
  • cmd/rhobs/rootCmd.go
  • cmd/servicelog/list.go
  • cmd/upgrade.go
  • main.go
✅ Files skipped from review due to trivial changes (19)
  • cmd/cluster/verifydns.go
  • cmd/rhobs/mcpCmd.go
  • cmd/dynatrace/dashboardCmd.go
  • cmd/cluster/etcd_health.go
  • cmd/dynatrace/urlCmd.go
  • cmd/iampermissions/get.go
  • cmd/cluster/detachstuckvolume.go
  • cmd/alerts/silence/silence_org.go
  • cmd/iampermissions/diff.go
  • cmd/alerts/list_alerts.go
  • cmd/alerts/silence/add_silence.go
  • cmd/cluster/checkbanneduser.go
  • cmd/cluster/support/delete.go
  • cmd/alerts/silence/list_silence.go
  • cmd/cluster/transferowner.go
  • cmd/cluster/context.go
  • cmd/servicelog/list.go
  • cmd/cluster/loggingcheck.go
  • cmd/cluster/access/access.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • cmd/cluster/access/cleanup.go
  • main.go
  • cmd/account/rotate-secret.go
  • cmd/iampermissions/save.go
  • cmd/cluster/support/status.go
  • cmd/alerts/silence/clear_silence.go

clcollins and others added 5 commits June 8, 2026 19:05
Required flags like --reason and --cluster-id were missing from command
examples, causing users to copy-paste incomplete invocations and hit
confusing errors. Additionally, missing-flag errors were buried under
a wall of usage text, and printed twice (once by cobra, once by main).

- Add SilenceUsage in PersistentPreRun so missing-flag and RunE errors
  no longer dump full usage text (unknown commands/flags still show it)
- Replace duplicate error print in main.go with a help hint
- Add Example fields to 37 commands that had required flags but no examples
- Move examples from Long field to Example field where misplaced
- Fix incorrect shorthand (-c vs -C) in resize control-plane example
- Standardize all placeholders to ${VARIABLE} style (no hard-coded
  ticket numbers or angle-bracket placeholders in examples)
- Add regression test that walks the command tree and validates all
  required flags appear in their command's Example field

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
CodeRabbit review fixes:
- Add --level firing example to alerts list
- Fix typos in Long descriptions: "specfic" -> "specific", "ectd" -> "etcd"
- Use ${OHSS} placeholder for --ohss flag instead of ${REASON}
- Guard against nil resolved command in main.go error path

Pre-existing lint fixes:
- evidence/collect.go: replace WriteString(Sprintf(...)) with Fprintf (staticcheck QF1012)
- account/cli.go: suppress gosec G117 false positive on credential output
- promote/rhobs/rhobs.go: suppress gosec G703 false positive on hardcoded paths
- pkg/utils/ocm_test.go: suppress gosec G117 false positive on test fixtures

Regenerate docs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address Mate's review: the PR 911 main.go change caused duplicate
"Run ... --help" hints for unknown commands and swallowed errors
entirely for commands with SilenceErrors: true (rhobs, org, upgrade).

- Fix main.go to print hint only when SilenceUsage is set (i.e.
  PersistentPreRun ran on a valid command), avoiding duplication
- Remove SilenceErrors: true from all 15 commands — none had a
  documented reason and it was boilerplate from initial implementations
- Keep SilenceUsage: true on mcp server/config for MCP protocol safety

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@clcollins clcollins force-pushed the worktree-snappy-jingling-elephant branch from 4553bb3 to 3b0cf32 Compare June 9, 2026 05:07
@openshift-ci openshift-ci Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 9, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
cmd/iampermissions/save.go (1)

49-50: ⚡ Quick win

Consider using placeholder variables for consistency.

The example uses literal values /tmp/policies and 4.15.0 instead of placeholder variables like ${DIR} and ${RELEASE_VERSION}. Other commands in this PR consistently use the ${VARIABLE} placeholder style (e.g., ${CLUSTER_ID}, ${OU_ID}, ${REASON}).

♻️ Suggested alignment with placeholder style
-  # Save IAM permissions to a directory
-  osdctl iampermissions save --dir /tmp/policies --release-version 4.15.0`,
+  # Save IAM permissions to a directory
+  osdctl iampermissions save --dir ${DIR} --release-version ${RELEASE_VERSION}`,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/iampermissions/save.go` around lines 49 - 50, The example in the help
text uses hard-coded values; update the example string in
cmd/iampermissions/save.go to use placeholder variables for consistency (replace
`/tmp/policies` with `${DIR}` and `4.15.0` with `${RELEASE_VERSION}`),
preserving the existing formatting and backticks around the full command so it
matches other examples that use `${VARIABLE}` style.
cmd/account/cli.go (1)

109-109: 💤 Low value

Suppression is appropriate; consider clarifying the comment.

The //nolint:gosec suppression is correct for this use case—the command's purpose is to output temporary AWS credentials to stdout for CLI consumption. However, the phrase "G117 false positive" is slightly misleading: gosec correctly detected credential output; this is intentional behavior rather than an incorrect detection (false positive).

📝 Optional: rephrase for accuracy
-		if err := enc.Encode(out); err != nil { //nolint:gosec // G117 false positive — intentionally outputting AWS credentials
+		if err := enc.Encode(out); err != nil { //nolint:gosec // G117 - intentional: CLI outputs temporary credentials to stdout
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/account/cli.go` at line 109, Update the inline lint suppression on the
enc.Encode(out) call to clearly state that the G117 gosec finding is expected
and intentional because this command purposefully outputs temporary AWS
credentials for CLI consumption; replace "G117 false positive" with a concise
justification like "intentionally outputting temporary AWS credentials for CLI
use — safe/expected" and keep the existing //nolint:gosec annotation on
enc.Encode to avoid silencing other checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/osdctl_alert_list.md`:
- Around line 15-24: The examples in the snippet use the plural command "osdctl
alerts list" while the page title/synopsis use "osdctl alert list"; update all
example lines to use the singular "osdctl alert list" so they match the
synopsis/title and prevent broken copy/paste, i.e., replace each occurrence of
"osdctl alerts list" in the shown examples with "osdctl alert list".

In `@docs/osdctl_alert_silence_add.md`:
- Around line 15-24: Update the example commands to use the documented command
path "osdctl alert silence add" instead of "osdctl alerts silence add"; locate
the examples shown (three occurrences of the example command) and replace each
"osdctl alerts silence add" with "osdctl alert silence add" so the examples
(including the flags --cluster-id, --alertname, --all, --duration, --comment,
--reason) match the documented command path exactly.

In `@docs/osdctl_servicelog_list.md`:
- Around line 9-11: Update the synopsis placeholder to use the same style as the
examples: replace the `<cluster-identifier>` placeholder in the command string
`osdctl servicelog list --cluster-id <cluster-identifier> [flags] [options]`
with `${CLUSTER_ID}` so the synopsis matches the examples and avoids mixed
placeholder formats.

---

Nitpick comments:
In `@cmd/account/cli.go`:
- Line 109: Update the inline lint suppression on the enc.Encode(out) call to
clearly state that the G117 gosec finding is expected and intentional because
this command purposefully outputs temporary AWS credentials for CLI consumption;
replace "G117 false positive" with a concise justification like "intentionally
outputting temporary AWS credentials for CLI use — safe/expected" and keep the
existing //nolint:gosec annotation on enc.Encode to avoid silencing other
checks.

In `@cmd/iampermissions/save.go`:
- Around line 49-50: The example in the help text uses hard-coded values; update
the example string in cmd/iampermissions/save.go to use placeholder variables
for consistency (replace `/tmp/policies` with `${DIR}` and `4.15.0` with
`${RELEASE_VERSION}`), preserving the existing formatting and backticks around
the full command so it matches other examples that use `${VARIABLE}` style.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e9f70ed1-c9a5-4e61-bbf1-2d14f6dd6cbe

📥 Commits

Reviewing files that changed from the base of the PR and between 4553bb3 and 3b0cf32.

📒 Files selected for processing (117)
  • cmd/account/cli.go
  • cmd/account/rotate-secret.go
  • cmd/alerts/list_alerts.go
  • cmd/alerts/silence/add_silence.go
  • cmd/alerts/silence/clear_silence.go
  • cmd/alerts/silence/list_silence.go
  • cmd/alerts/silence/silence_org.go
  • cmd/cloudtrail/errors.go
  • cmd/cloudtrail/permission-denied.go
  • cmd/cluster/access/access.go
  • cmd/cluster/access/cleanup.go
  • cmd/cluster/cad/run.go
  • cmd/cluster/changevolumetype.go
  • cmd/cluster/checkbanneduser.go
  • cmd/cluster/context.go
  • cmd/cluster/detachstuckvolume.go
  • cmd/cluster/etcd_health.go
  • cmd/cluster/etcd_replace.go
  • cmd/cluster/getenvvars.go
  • cmd/cluster/health.go
  • cmd/cluster/hypershift_info.go
  • cmd/cluster/loggingcheck.go
  • cmd/cluster/reports/create.go
  • cmd/cluster/reports/get.go
  • cmd/cluster/reports/list.go
  • cmd/cluster/resize/controlplane_node.go
  • cmd/cluster/resize/infra_node.go
  • cmd/cluster/resize/requestserving_node.go
  • cmd/cluster/snapshot.go
  • cmd/cluster/ssh/key.go
  • cmd/cluster/support/delete.go
  • cmd/cluster/support/post.go
  • cmd/cluster/support/status.go
  • cmd/cluster/transferowner.go
  • cmd/cluster/validatepullsecretext.go
  • cmd/cluster/verifydns.go
  • cmd/cmd.go
  • cmd/cost/create.go
  • cmd/cost/list.go
  • cmd/cost/reconcile.go
  • cmd/dynatrace/dashboardCmd.go
  • cmd/dynatrace/urlCmd.go
  • cmd/evidence/collect.go
  • cmd/hcp/backup/backup.go
  • cmd/hcp/get-cp-autoscaling-status/get_cp_autoscaling_status.go
  • cmd/hcp/mustgather/mustGather.go
  • cmd/hcp/status/status.go
  • cmd/iampermissions/diff.go
  • cmd/iampermissions/get.go
  • cmd/iampermissions/save.go
  • cmd/org/aws-accounts.go
  • cmd/org/clusters.go
  • cmd/org/current.go
  • cmd/org/customers.go
  • cmd/org/describe.go
  • cmd/org/get.go
  • cmd/org/labels.go
  • cmd/org/users.go
  • cmd/promote/rhobs/rhobs.go
  • cmd/required_flags_test.go
  • cmd/rhobs/cellCmd.go
  • cmd/rhobs/logsCmd.go
  • cmd/rhobs/mcpCmd.go
  • cmd/rhobs/metricsCmd.go
  • cmd/rhobs/rootCmd.go
  • cmd/servicelog/list.go
  • cmd/upgrade.go
  • docs/README.md
  • docs/osdctl_account_rotate-secret.md
  • docs/osdctl_alert_list.md
  • docs/osdctl_alert_silence_add.md
  • docs/osdctl_alert_silence_expire.md
  • docs/osdctl_alert_silence_list.md
  • docs/osdctl_alert_silence_org.md
  • docs/osdctl_cloudtrail_errors.md
  • docs/osdctl_cloudtrail_permission-denied-events.md
  • docs/osdctl_cluster_break-glass.md
  • docs/osdctl_cluster_break-glass_cleanup.md
  • docs/osdctl_cluster_cad_run.md
  • docs/osdctl_cluster_change-ebs-volume-type.md
  • docs/osdctl_cluster_check-banned-user.md
  • docs/osdctl_cluster_context.md
  • docs/osdctl_cluster_detach-stuck-volume.md
  • docs/osdctl_cluster_etcd-health-check.md
  • docs/osdctl_cluster_etcd-member-replace.md
  • docs/osdctl_cluster_get-env-vars.md
  • docs/osdctl_cluster_health.md
  • docs/osdctl_cluster_hypershift-info.md
  • docs/osdctl_cluster_logging-check.md
  • docs/osdctl_cluster_reports_create.md
  • docs/osdctl_cluster_reports_get.md
  • docs/osdctl_cluster_reports_list.md
  • docs/osdctl_cluster_resize_control-plane.md
  • docs/osdctl_cluster_resize_infra.md
  • docs/osdctl_cluster_resize_request-serving-nodes.md
  • docs/osdctl_cluster_snapshot.md
  • docs/osdctl_cluster_ssh_key.md
  • docs/osdctl_cluster_support_delete.md
  • docs/osdctl_cluster_support_post.md
  • docs/osdctl_cluster_support_status.md
  • docs/osdctl_cluster_transfer-owner.md
  • docs/osdctl_cluster_validate-pull-secret-ext.md
  • docs/osdctl_cluster_verify-dns.md
  • docs/osdctl_cost_create.md
  • docs/osdctl_cost_list.md
  • docs/osdctl_cost_reconcile.md
  • docs/osdctl_evidence_collect.md
  • docs/osdctl_hcp_backup.md
  • docs/osdctl_hcp_get-cp-autoscaling-status.md
  • docs/osdctl_hcp_must-gather.md
  • docs/osdctl_hcp_status.md
  • docs/osdctl_iampermissions_diff.md
  • docs/osdctl_iampermissions_get.md
  • docs/osdctl_iampermissions_save.md
  • docs/osdctl_servicelog_list.md
  • main.go
  • pkg/utils/ocm_test.go
✅ Files skipped from review due to trivial changes (40)
  • cmd/alerts/silence/list_silence.go
  • cmd/cluster/etcd_replace.go
  • cmd/cluster/loggingcheck.go
  • docs/osdctl_hcp_get-cp-autoscaling-status.md
  • cmd/cloudtrail/errors.go
  • cmd/cluster/verifydns.go
  • docs/osdctl_cloudtrail_errors.md
  • docs/osdctl_cluster_validate-pull-secret-ext.md
  • docs/osdctl_cluster_resize_control-plane.md
  • cmd/cluster/support/status.go
  • docs/osdctl_cluster_snapshot.md
  • cmd/iampermissions/diff.go
  • cmd/dynatrace/urlCmd.go
  • cmd/cluster/context.go
  • docs/osdctl_cluster_change-ebs-volume-type.md
  • cmd/cluster/detachstuckvolume.go
  • docs/osdctl_cluster_resize_infra.md
  • docs/osdctl_evidence_collect.md
  • cmd/cluster/resize/controlplane_node.go
  • cmd/cluster/checkbanneduser.go
  • cmd/cluster/access/access.go
  • cmd/cluster/reports/get.go
  • cmd/iampermissions/get.go
  • docs/osdctl_cluster_ssh_key.md
  • cmd/org/users.go
  • cmd/cluster/ssh/key.go
  • docs/osdctl_hcp_must-gather.md
  • cmd/cluster/reports/create.go
  • pkg/utils/ocm_test.go
  • cmd/cluster/health.go
  • cmd/cluster/support/delete.go
  • cmd/hcp/get-cp-autoscaling-status/get_cp_autoscaling_status.go
  • cmd/cluster/resize/infra_node.go
  • cmd/cluster/etcd_health.go
  • docs/osdctl_hcp_status.md
  • cmd/promote/rhobs/rhobs.go
  • cmd/alerts/silence/clear_silence.go
  • cmd/cost/create.go
  • cmd/cluster/resize/requestserving_node.go
  • cmd/dynatrace/dashboardCmd.go
🚧 Files skipped from review as they are similar to previous changes (32)
  • cmd/hcp/mustgather/mustGather.go
  • cmd/cloudtrail/permission-denied.go
  • cmd/cluster/snapshot.go
  • cmd/org/clusters.go
  • cmd/cluster/reports/list.go
  • cmd/alerts/silence/add_silence.go
  • cmd/account/rotate-secret.go
  • cmd/hcp/backup/backup.go
  • docs/osdctl_cluster_resize_request-serving-nodes.md
  • cmd/rhobs/mcpCmd.go
  • cmd/cluster/access/cleanup.go
  • cmd/cluster/changevolumetype.go
  • cmd/rhobs/logsCmd.go
  • cmd/hcp/status/status.go
  • cmd/cluster/cad/run.go
  • cmd/servicelog/list.go
  • cmd/alerts/list_alerts.go
  • docs/osdctl_hcp_backup.md
  • docs/osdctl_cluster_support_post.md
  • cmd/org/describe.go
  • main.go
  • cmd/alerts/silence/silence_org.go
  • cmd/org/aws-accounts.go
  • cmd/rhobs/metricsCmd.go
  • cmd/org/current.go
  • cmd/cluster/hypershift_info.go
  • cmd/rhobs/cellCmd.go
  • cmd/cmd.go
  • cmd/evidence/collect.go
  • cmd/org/labels.go
  • cmd/cluster/validatepullsecretext.go
  • cmd/required_flags_test.go

Comment thread docs/osdctl_alert_list.md
Comment on lines +15 to +24
```
# List all alerts for a cluster
osdctl alerts list --cluster-id ${CLUSTER_ID} --reason "${REASON}"

# List only firing alerts
osdctl alerts list --cluster-id ${CLUSTER_ID} --level firing --reason "${REASON}"

# List only critical alerts
osdctl alerts list --cluster-id ${CLUSTER_ID} --level critical --reason "${REASON}"
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix command name mismatch in examples (alerts vs alert).

Examples use osdctl alerts list, but this page’s synopsis and title use osdctl alert list. Keep them consistent to avoid broken copy/paste usage.

🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 15-15: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/osdctl_alert_list.md` around lines 15 - 24, The examples in the snippet
use the plural command "osdctl alerts list" while the page title/synopsis use
"osdctl alert list"; update all example lines to use the singular "osdctl alert
list" so they match the synopsis/title and prevent broken copy/paste, i.e.,
replace each occurrence of "osdctl alerts list" in the shown examples with
"osdctl alert list".

Comment on lines +15 to +24
```
# Silence a specific alert
osdctl alerts silence add --cluster-id ${CLUSTER_ID} --alertname "KubePodNotReady" --reason "${REASON}"

# Silence all alerts for a cluster
osdctl alerts silence add --cluster-id ${CLUSTER_ID} --all --reason "${REASON}"

# Silence an alert with custom duration and comment
osdctl alerts silence add --cluster-id ${CLUSTER_ID} --alertname "KubePodNotReady" --duration 2h --comment "Investigating pod issue" --reason "${REASON}"
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Correct example command path to match documented command.

Examples use osdctl alerts silence add, while this command page documents osdctl alert silence add. Align the examples with the documented command path.

🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 15-15: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/osdctl_alert_silence_add.md` around lines 15 - 24, Update the example
commands to use the documented command path "osdctl alert silence add" instead
of "osdctl alerts silence add"; locate the examples shown (three occurrences of
the example command) and replace each "osdctl alerts silence add" with "osdctl
alert silence add" so the examples (including the flags --cluster-id,
--alertname, --all, --duration, --comment, --reason) match the documented
command path exactly.

Comment on lines +9 to +11
```
osdctl servicelog list --cluster-id <cluster-identifier> [flags] [options]
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Unify synopsis placeholder style with examples.

Line 10 uses <cluster-identifier> while Lines 17/20/23 use ${CLUSTER_ID}. Keep one style (prefer ${CLUSTER_ID}) to avoid conflicting docs patterns.

🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 9-9: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/osdctl_servicelog_list.md` around lines 9 - 11, Update the synopsis
placeholder to use the same style as the examples: replace the
`<cluster-identifier>` placeholder in the command string `osdctl servicelog list
--cluster-id <cluster-identifier> [flags] [options]` with `${CLUSTER_ID}` so the
synopsis matches the examples and avoids mixed placeholder formats.

@openshift-ci

openshift-ci Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@clcollins: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 10, 2026
@openshift-ci

openshift-ci Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants