miri icon indicating copy to clipboard operation
miri copied to clipboard

miri-script: use a proper CLI arg parsing tool

Open RalfJung opened this issue 1 year ago • 3 comments

We are currently using ad-hoc hand-written parsers for this, and it's kind of annoying. However, we tried to use clap, and it currently doesn't seem possible: what we'd like to do is that once there is a positional argument, that argument and everything that follows gets collected in Vec -- our flags, like --dep, need to come before all of them.

This is non-standard, as it makes ./miri run foo.rs --dep different from ./miri run --dep foo.rs. But it's kind of necessary as ./miri run (and a bunch of other commands) are wrappers around other, complicated tools for which we want to just forward all flags (including --) without parsing them ourselves.

Using clap here is blocked on https://github.com/clap-rs/clap/issues/5055. But maybe there's another crate we can use?

RalfJung avatar May 09 '24 13:05 RalfJung

With https://github.com/rust-lang/miri/pull/3621, our parser's behavior changed: ./miri run foo.rs --dep and ./miri run --dep foo.rs are now equivalent. However, we'd still like to preserve the -- and forward it to miri (e.g. in ./miri run foo.rs -- arg1 arg2), so we still can't use clap.

RalfJung avatar May 19 '24 16:05 RalfJung

Would it make any sense to split the argv in the before and after -- part, and use clap::Parser::parse_from for the first part, and forward the second part?

Mandragorian avatar Nov 15 '24 22:11 Mandragorian

Maybe? Not sure how ugly that would be.

Also, thinking about this now I realize adding clap would likely significantly increase the build times for miri-script. So maybe the current solution isn't such a bad tradeoff after all.

RalfJung avatar Nov 16 '24 07:11 RalfJung