-
Notifications
You must be signed in to change notification settings - Fork 6
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
Provide arguments through struct which can also be parsed through Clap
#15
Conversation
ping @MarijnS95 wdyt? |
@MarijnS95 had time to take a look yet? |
@dvc94ch Not yet, I've only just returned and am already in over my head on other issues, but at a quick glance this looks very promising. I'll give it more thorough review in the off-hours, maybe later this week or over the weekend. Meanwhile, you know I'm a big fan of descriptive titles 😉 - how about something like |
Clap
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.
Overall very glad to see clap
support but I'm not sure we can get away with passing just the few arguments that we support to cargo
, and that's not very future-proof either?
Additionally the [lib]
change should IMO be done in a separate (fllowup?) PR for easier review and discussion, as this is a bit bigger topic that should be solved for [[bin]]
at the same time.
src/args.rs
Outdated
pub fn apply(&self, cmd: &mut Command) { | ||
if self.quiet { | ||
cmd.arg("--quiet"); | ||
} | ||
if self.release { | ||
cmd.arg("--release"); | ||
} | ||
if let Some(target) = self.target.as_ref() { | ||
cmd.arg("--target").arg(target); | ||
} | ||
if let Some(profile) = self.profile.as_ref() { | ||
cmd.arg("--profile").arg(profile.to_string()); | ||
} | ||
for example in &self.example { | ||
cmd.arg("--example").arg(example); | ||
} | ||
if self.examples { | ||
cmd.arg("--examples"); | ||
} | ||
for bin in &self.bin { | ||
cmd.arg("--bin").arg(bin); | ||
} | ||
if self.bins { | ||
cmd.arg("--bins"); | ||
} | ||
if let Some(package) = self.package.as_ref() { | ||
cmd.arg("--package").arg(package); | ||
} | ||
if let Some(target_dir) = self.target_dir.as_ref() { | ||
cmd.arg("--target-dir").arg(target_dir); | ||
} | ||
if let Some(manifest_path) = self.manifest_path.as_ref() { | ||
cmd.arg("--manifest-path").arg(manifest_path); | ||
} | ||
} |
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.
Seems to be fine for now, but it's a bit of hand-writing and should be carefully maintained when new fields are added. As mentioned https://github.com/rust-windowing/android-ndk-rs/pull/238/files#r832076774 I think we should keep passing the original array of arguments as-is. I don't think we have any cargo-apk
-specific fields that need to be filtered out, and it is probably possible for clap
to give us an unparsed array of all cmdline arguments that follow after parsing the initial subcommand
selections?
Alternatively I have a serde::Serializer
implementation locally that generates a cmdline (which we use internally for many, many structures that are all parsable through clap) which I could share or publish as a separate crate.
The only downside is requiring serde
as an unconditional dependency here to make this work.
(That said, this apply()
function is probably mandatory for the case where the caller constructs the Args
struct directly by hand instead of having a list of string arguments that can be parsed through clap)
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.
don't think all args should be passed to cargo. it is possible for a subcommand to have it's own args that cargo doesn't understand.
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.
We don't have any for the time being. And it seems this PR misses some high-grossing flags like those relating to feature flags. Those should undoubtedly be passed to cargo
.
Fwiw the |
Another thing that jumps to mind: is there any possibility that we could get Even better would be if |
I think the correct way to do it would be to support something like |
I found some mentions on the
Not sure about that since the user should be oblivious to whether The only tricky bit seems getting everything after the If it wasn't for the few prefixed clap subcommand things, we could just pass |
I disagree. This causes confusion. Now when using clap all the args |
For the time being I agree that it should be clear what The bit you quoted is where I specifically condemn the (ab)use of |
well I added the missing args, but looks like the logic/api will need to get quite a bit more complicated now. I think we need something like this:
really don't have time to work on this at the moment, do you want to take over? |
Don't worry about that for now. Let's keep this PR exclusively about migrating to What of the above made you expand EDIT: Yes I guess for |
Well, cargo-subcommand assumes that we're building one package. But cargo supports taking multiple packages as args. Each package has it's own manifest. So |
@dvc94ch Right, I only thought about adding |
Co-authored-by: Marijn Suijten <[email protected]>
So this performs the refactoring we discussed and adds support for
[lib] name