-
Notifications
You must be signed in to change notification settings - Fork 306
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
Add new built-in flag --dump-help
#310
Conversation
This commit will add a new builtin option named `--dump-help-info` which outputs help information in JSON.
@natecook1000 Please take a look when you have time. Thank you! Edit: I have resolved the conflicts so please take a look. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good start, @KS1019! I haven't gotten a chance to review DumpHelpInfoGenerator
yet, but wanted to give you a couple notes here.
// Look for `--dump-help` | ||
guard !split.contains(Name.long("dump-help")) else { | ||
throw DumpHelpInfoRequested() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather handle this the same way as --version
rather than than going through than separate DumpHelpInfoCommand
command. HelpCommand
exists so that you can write things like example help sub1 sub2
, but that won't be the case here, it's just a short-circuiting flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At 4d97d0c, I modified the code to throw CommandError like --version
does. I will look into more if I can remove DumpHelpInfoCommand completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed DumpHelpInfoRequested and DumpHelpInfoCommand at 9825ecb
@@ -185,6 +185,7 @@ internal struct HelpGenerator { | |||
optionElements.append(element) | |||
} | |||
} | |||
optionElements.append(.init(label: "--dump-help", abstract: "Dump help information.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave this out of the help screen for now. I'd like to eventually add a version of the help screen that includes hidden flags, etc (via something like example --help --all
or example --help-all
), so this could show up as part of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed at 40de584
@_implementationOnly import Foundation | ||
|
||
internal struct DumpHelpInfoGenerator { | ||
struct CommandInfo: Codable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think CommandInfo
and ArgumentInfo
will probably be independently useful — can you move them out to be top-level types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed at 94a81ed
var isDefault: Bool? | ||
} | ||
|
||
var command: ArgumentInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not re-use this for the command's metadata — should be okay to just put the command-specific details right here instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed at 9c8e5a7
@swift-ci Please test |
Hi @natecook1000 |
@swift-ci Please test |
@swift-ci Please test Linux platform |
It seems that tests are failing on the Linux Platform because specifying only I am considering adding Alternatively, I think we can change how we test the generated JSON from comparing them as strings to comparing them as values by converting them back to the codable values. I would love to know what do your think the best way would be to solve the problem! |
@KS1019 I think it would be fine to round trip through JSON and check for equality with the expectation that way. String equality for JSON is definitely tricky due to its order independence. Thanks! |
…ommandInfo as public.
@natecook1000 |
…into dump-help-info
@swift-ci Please test |
Repair the build after apple#310 to allow building with CMake which is required for bootstrapping.
This regressed the Windows build :-( (#336 should repair that) |
Repair the build after #310 to allow building with CMake which is required for bootstrapping.
This PR resolves #164 and adds a new built-in flag
--dump-help
to dump all the help information in JSON format. This feature can be useful when parsing help information and generating documentation for a command. I will add documentation if necessary. In that case, I would appreciate it if anyone could direct me to the right place to add the documentation.Checklist