Skip to content

fix CLI help example indentation#28196

Merged
lsm5 merged 1 commit intocontainers:mainfrom
MayorFaj:bug/28178-fix-cli-help-example-indentation
Mar 9, 2026
Merged

fix CLI help example indentation#28196
lsm5 merged 1 commit intocontainers:mainfrom
MayorFaj:bug/28178-fix-cli-help-example-indentation

Conversation

@MayorFaj
Copy link
Copy Markdown
Contributor

@MayorFaj MayorFaj commented Mar 4, 2026

Description

Go backtick (raw) string literals preserve all whitespace verbatim, including tabs and spaces from source code indentation. When Cobra renders the Example field in --help output, multi-line examples that were indented in source appeared with incorrect whitespace, some had tabs, others had 3 spaces, and some were flush-left.

Fix: Added an indentExamples template function registered via cobra.AddTemplateFunc that normalizes all Example strings to exactly 2-space indentation and strips leading/trailing blank lines. Updated the usage template to pipe through this function ({{.Example | indentExamples}}), and converted all ~95 multi-line Example fields across podman to flush-left raw strings so the template function handles indentation uniformly.

This is a defensive, centralized approach, future contributors simply write flush-left example strings in backticks, and the template function ensures correct display.

Checklist

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all
    commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #28178 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

Fixed CLI `--help` output where multi-line command examples were incorrectly indented due to Go raw string literal whitespace being preserved verbatim. All examples now render with consistent 2-space indentation.

Fixes: #28178

@MayorFaj MayorFaj force-pushed the bug/28178-fix-cli-help-example-indentation branch from a3d4d09 to ae8c370 Compare March 4, 2026 22:04
@packit-as-a-service
Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@jankaluza
Copy link
Copy Markdown
Member

I think I like it. LGTM.

Copy link
Copy Markdown
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

LGTM overall, just two minor style comments (non-blocking).

Comment thread cmd/podman/root.go Outdated
Comment thread cmd/podman/root_test.go Outdated
Copy link
Copy Markdown
Member

@lsm5 lsm5 left a comment

Choose a reason for hiding this comment

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

change LGTM.

Please squash into a single commit after addressing other comments.

Comment thread cmd/podman/root.go Outdated
@MayorFaj MayorFaj force-pushed the bug/28178-fix-cli-help-example-indentation branch from f5a8968 to 8b3f2de Compare March 5, 2026 19:53
@MayorFaj MayorFaj requested review from Honny1, Luap99 and lsm5 March 5, 2026 19:56
@MayorFaj MayorFaj changed the title fix command examples formatting across various Podman commands fix CLI help example indentation Mar 5, 2026
@TomSweeneyRedHat
Copy link
Copy Markdown
Member

LGTM
And my OCD loves it!
I've restarted the failing tests. Definite flakes due to some Google servers being unavailable.

@TomSweeneyRedHat
Copy link
Copy Markdown
Member

@MayorFaj, I think you may be running into an issue with our build machines that was fixed earlier today. Could you please rebase and try pushing again?

@MayorFaj MayorFaj force-pushed the bug/28178-fix-cli-help-example-indentation branch from 8b3f2de to dbc9ea6 Compare March 6, 2026 00:53
@MayorFaj
Copy link
Copy Markdown
Contributor Author

MayorFaj commented Mar 6, 2026

LGTM And my OCD loves it! I've restarted the failing tests. Definite flakes due to some Google servers being unavailable.
Glad the cleanup scratches that itch 😄. Appreciate the review

@MayorFaj
Copy link
Copy Markdown
Contributor Author

MayorFaj commented Mar 6, 2026

@MayorFaj, I think you may be running into an issue with our build machines that was fixed earlier today. Could you please rebase and try pushing again?

done

Comment thread cmd/podman/root.go
@lsm5
Copy link
Copy Markdown
Member

lsm5 commented Mar 6, 2026

@MayorFaj could you PTAL at the failing tests?

Comment thread cmd/podman/root_test.go Outdated
Comment thread cmd/podman/root_test.go Outdated
Signed-off-by: MayorFaj <mayorfaj@gmail.com>
@MayorFaj MayorFaj force-pushed the bug/28178-fix-cli-help-example-indentation branch from 5a90ffb to 31b956e Compare March 6, 2026 21:06
@MayorFaj
Copy link
Copy Markdown
Contributor Author

MayorFaj commented Mar 7, 2026

@MayorFaj could you PTAL at the failing tests?

all good now, the only failing test is not related to the PR

Copy link
Copy Markdown
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

LGTM. I reran the failed tests.

Copy link
Copy Markdown
Member

@lsm5 lsm5 left a comment

Choose a reason for hiding this comment

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

LGTM

@lsm5 lsm5 merged commit 5685ac5 into containers:main Mar 9, 2026
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation: Examples after the first one are indented inappropriately

7 participants