You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Inconsistent visibility string interpolation in generateHelpNames for .longWithSingleDash vs .long names #901
In Sources/ArgumentParser/Usage/HelpGenerator.swift, the generateHelpNames(visibility:) method on NameSpecification handles the .long and .longWithSingleDash cases inconsistently when generating non-default visibility help flag names.
fileprivatefunc generateHelpNames(visibility:ArgumentVisibility)->[Name]{self.makeNames(InputKey(name:"help", parent:nil)).compactMap{ name inguard visibility.base !=.default else{return name }switch name {case.long(let helpName):return.long("\(helpName)-\(visibility.base)") // ✅ uses visibility.base
case.longWithSingleDash(let helpName):return.longWithSingleDash("\(helpName)-\(visibility)") // ❌ uses visibility (full), not visibility.base
case.short:returnnil}}.sorted(by:>)}
The .long case correctly appends visibility.base (e.g., "hidden")
The .longWithSingleDash case appends the full visibility description instead of visibility.base
This means if a command uses single-dash long names (e.g., -help), the generated hidden/private help flag name would be different from what the double-dash variant generates, causing inconsistent CLI behavior where -help-hidden does not behave the same as --help-hidden.
Steps to Reproduce
Create a command that uses .longWithSingleDash in its helpNames configuration
Call the command with a non-default visibility help flag
Observe the appended suffix differs from the .long variant
Expected Behavior
Both .long and .longWithSingleDash cases should use visibility.base for consistent flag name generation:
case .longWithSingleDash(let helpName):
return .longWithSingleDash("\(helpName)-\(visibility.base)") // ✅ fix: use .base
Environment
swift-argument-parser version: main branch (commit af51a49)
Swift version: 5.9+
Platform: All platforms
Impact
Low-to-medium. Affects only commands that configure helpNames with .longWithSingleDash at non-default visibility levels, but the inconsistency is a latent bug that could surface in toolchains and developer tools built on top of this library.
Reported after manual code review of HelpGenerator.swift.
The change is a single-line correction — replacing visibility with visibility.base in the .longWithSingleDash case of generateHelpNames, making it consistent with the .long case that already correctly uses visibility.base.
Happy to add a test case for this if the team would like one before merging. Let me know!
Activity
AkshatRaj00 commentedon May 23, 2026
I've submitted a fix for this in PR #902.
The change is a single-line correction — replacing
visibilitywithvisibility.basein the.longWithSingleDashcase ofgenerateHelpNames, making it consistent with the.longcase that already correctly usesvisibility.base.Happy to add a test case for this if the team would like one before merging. Let me know!
aniketatgithub commentedon Oct 6, 2026
I can reproduce this — taking it on. Opening a PR with the fix shortly.