Skip to content

Conversation

caarlos0
Copy link
Member

@caarlos0 caarlos0 commented Jun 26, 2025

this properly handles examples to sub commands, as well as show the full path in places it probably should.

on top of that, it improves testing, which wasn't working properly due to root cmd not being a pointer.

Looks like this:

CleanShot 2025-06-26 at 14 30 20@2x

CleanShot 2025-06-26 at 14 34 17@2x

closes #45
closes #44

@caarlos0 caarlos0 self-assigned this Jun 26, 2025
@caarlos0 caarlos0 requested a review from Copilot June 26, 2025 17:34
@caarlos0 caarlos0 added the bug Something isn't working label Jun 26, 2025
@caarlos0 caarlos0 marked this pull request as ready for review June 26, 2025 17:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves sub-command styling in help/man outputs, displays full command paths in examples, and refactors testing to use pointer‐based root commands.

  • Replace generic placeholder names in golden files and add new golden outputs for nested subcommands
  • Update styleUsage and styleExample to use full paths and UseLine(), and refactor isSubCommand
  • Simplify version logic in Execute via buildVersion and convert many tests to use toMkroot helpers

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
testdata/TestSetup/with_subcommands/*.golden Updated expected help outputs for subcommands and examples
testdata/TestSetup/complete/man.golden Changed manpage title and usage to include man subcommand
help.go Switched to UseLine() for usage, enhanced subcommand styling, updated isSubCommand signature
fang.go Extracted version-building logic into buildVersion and wire-up in Execute
fang_test.go Refactored tests to use toMkroot wrappers and Go 1.24’s T.Context()
example/main.go Added examples for nested subcommands
Comments suppressed due to low confidence (2)

fang.go:147

  • The new buildVersion function has branching logic for default and VCS-based versions; consider adding unit tests to cover both code paths.
func buildVersion(opts settings) string {

help.go:288

  • cleanArgs currently accumulates all tokens including flags and quoted strings, which can break command traversal; consider appending only actual subcommand names to the path.
		cleanArgs = append(cleanArgs, arg)

@caarlos0 caarlos0 merged commit c01daea into main Jun 26, 2025
18 checks passed
@caarlos0 caarlos0 deleted the fix branch June 26, 2025 18:59
@hellt
Copy link

hellt commented Jul 21, 2025

Hi @caarlos0
this PR bumped Go to 1.24.0 and I wonder if that was required?

As Go uses the N-1 support matrix typically it would be great to stay on 1.23 until 1.25 is GA and have other libs to not be forced to jump on latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing bug in example text Option for full Usage path in help
3 participants