Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default display in help for EnumerableFlag and other types #486

Merged
merged 6 commits into from Sep 14, 2022

Conversation

natecook1000
Copy link
Member

When an EnumerableFlag flag has a default value, the default is printed incorrectly as the instance value in the help, instead of as the flag that a user would need to type. The same issue is present for Boolean flags with both an inversion and a default.

struct Example: ParsableCommand {
   @Flag(inversion: .prefixedNo)
   var frobulate: Bool = true
}

Old help output:

USAGE: example [--frobulate] [--no-frobulate]

OPTIONS:
  --frobulate/--no-frobulate
                          Whether to frobulate. (default: true)
  -h, --help              Show help information.

Corrected help output:

USAGE: example [--frobulate] [--no-frobulate]

OPTIONS:
  --frobulate/--no-frobulate
                          Whether to frobulate. (default: --frobulate)
  -h, --help              Show help information.

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

In the help for flags like --prefix/--no-prefix, use the name of the
default flag instead of true/false.
When EnumerableFlag types have separate help strings, show the correct
default flag name on the default flag in the help.
@rauhul
Copy link
Contributor

rauhul commented Sep 9, 2022

Ooh this is a nice fix!

@natecook1000
Copy link
Member Author

Will almost certainly conflict with #477, let's land that first!

# Conflicts:
#	Sources/ArgumentParser/Parsable Properties/Flag.swift
#	Sources/ArgumentParser/Parsing/ArgumentSet.swift
#	Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit 7506042 into apple:main Sep 14, 2022
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.

None yet

2 participants