-
Notifications
You must be signed in to change notification settings - Fork 263
Make c2rust
just forward args to discovered subcommands
#579
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rinon
reviewed
Aug 23, 2022
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.
This looks good. Can you paste an example of what a bare c2rust
invocation with no args looks like now? Would save me pulling this down and building it, thanks.
❯ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/c2rust`
C2Rust v0.16.0+904 (7bab0a01b 2022-08-04) dirty 2 modifications
The C2Rust Project Developers <[email protected]>
USAGE:
c2rust <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
analyze
help Prints this message or the help of the given subcommand(s)
instrument
pdg
transpile |
… parsing in the `c2rust` binary.
…e explanations to comments.
… a `None` on the first `args.next()`.
7bab0a0
to
3cacb96
Compare
…::to_str` over `UtfPath::to_str` since we just want to skip the file, not error on it.
…()`s to make it cleaner and more concise.
5c48671
to
4ee2582
Compare
rinon
approved these changes
Aug 25, 2022
fw-immunant
approved these changes
Aug 25, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes
c2rust
to be a simpler wrapper around the otherc2rust-*
subcommand.Instead of
c2rust
having to know about all the subcommands and their arguments upfront,c2rust $subcommand $args
just runsc2rust-$subcommand $args
. This allowsc2rust instrument
to work as before (before #554), while also enablingc2rust analyze
andc2rust pdg
in the same way. Theclap
help messages are still preserved for the most part, except for the short help messages for the subcommands. Otherwise,c2rust --help
works as before (while also suggesting the new subcommands), andc2rust $subcommand --help
works by runningc2rust-$subcommand --help
(instead ofclap
intercepting the--help
).The way this is implemented is, first the
c2rust
binary's directory is searched for executables namedc2rust-*
to discover subcommands. This is combined with the simple list of known subcommands (["transpile", "instrument", "pdg", "analyze"]
) in case they're not discovered properly and we still want to suggest them. Then we check if the first argument is one of these subcommands. If it exists, we invoke it. If it doesn't exist, but is known, we suggest building it, and it doesn't exist and isn't known (or there was no subcommand given), then we run theclap
parser and let it handle arg parsing and nice error/help messages. The reason we don't have everything go throughclap
is that I couldn't figure out a way to haveclap
just forward all arguments, even ones like--metadata
with hyphens (Arg::allow_hyphen_values
didn't work), without requiring a leading--
argument.