Skip to content

Conversation

@marcleblanc2
Copy link
Contributor

@marcleblanc2 marcleblanc2 commented Nov 9, 2025

Usage / helper text was only printed for either src (top-level) or src <command> (command-level), ignoring any of the usage functions defined by subcommands.

For example, src snapshot upload --help would only output the usageFunc for src snapshot

With this change:

Any of the following will output the usageFunc for src snapshot upload

src snapshot upload --help
src snapshot --help upload
src --help snapshot upload

src snapshot upload -h
src snapshot -h upload
src -h snapshot upload

src snapshot upload help
src snapshot help upload
src help snapshot upload

Any of the following will output the usageFunc for src snapshot

src snapshot --help
src --help snapshot

src snapshot -h
src -h snapshot

src snapshot help
src help snapshot

Any of the following will output the usageFunc for src

src --help

src -h

src help

Test plan

@marcleblanc2 marcleblanc2 marked this pull request as draft November 10, 2025 00:37
@marcleblanc2 marcleblanc2 marked this pull request as ready for review November 10, 2025 09:58
@marcleblanc2 marcleblanc2 force-pushed the marc-fix-helper-text-for-sub-commands branch from a263401 to 794e0b6 Compare November 10, 2025 23:23
@marcleblanc2
Copy link
Contributor Author

Hey @bobheadxi or @keegancsmith, I'd like this to make it into the 6.10 release on Wednesday, if either of you has a moment to review, or lmk who else I should ask 🙏

Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

This is extremely complicated compared to what we had before. Looking at the code in src-cli it uses go's built in 'flag' apis. That only supports -h. If you do something like

src snapshot upload -h

it works correctly. The problem comes in is that we added in extra support for --help and reading that code you can see that is naively only supports the first level of subcommands, not deeper ones like src snapshot upload --help. Fixing that is the proper fix here.

I know you want to get this in, so I sent out this alternative fix. Mind testing it and seeing if it is acceptable? It doesn't exactly match all the use cases you mentioned, but should solve the main complaint you have. #1195

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tempDir := t.TempDir()
cmd := exec.Command(os.Args[0], "-test.run=^TestCommander_Run_HelpFlag$")
Copy link
Member

Choose a reason for hiding this comment

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

the pattern in this file of using subprocesses is very complicated for what you want to check. I'm guessing you did it because of the os.Exit in the code under test. Rather just make os.Exit something you can inject?

Copy link
Contributor Author

@marcleblanc2 marcleblanc2 Nov 11, 2025

Choose a reason for hiding this comment

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

I'm not aware of the difference, but Amp had picked this route so that it could validate the exit code.

src snapshot upload -h would return 0, whereas src snapshot upload would return 2 (input error).

Validating the return code is not the most material change, so if it's more complex than it's worth, it's fine to remove.

// Handle any errors returned
if err := cmd.handler(args); err != nil {

// If the returned error is of type UsageError
Copy link
Member

Choose a reason for hiding this comment

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

note: the introduction of all these comments does not make the code more readable and makes the PR much harder to review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted. I felt the code was rather cryptic to read.

@keegancsmith
Copy link
Member

Alternative was merged in.

@keegancsmith keegancsmith deleted the marc-fix-helper-text-for-sub-commands branch November 12, 2025 07:04
@marcleblanc2 marcleblanc2 restored the marc-fix-helper-text-for-sub-commands branch November 13, 2025 03:41
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.

3 participants