Skip to content

Commit

Permalink
Improve proxy argument parsing slightly (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
tedinski authored Jun 14, 2022
1 parent 6184f0e commit 49f4b33
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@ use anyhow::{bail, Context, Result};
/// `bin` should be either `kani` or `cargo-kani`
pub fn proxy(bin: &str) -> Result<()> {
// In an effort to keep our dependencies minimal, we do the bare minimum argument parsing
let args: Vec<_> = env::args_os().collect();
if args.len() >= 2 && args[1] == "setup" {
if args.len() >= 4 && args[2] == "--use-local-bundle" {
let args: Vec<OsString> = env::args_os().collect();
// This makes it easy to do crude arg parsing with match
let args_ez: Vec<Option<&str>> = args.iter().map(|x| x.to_str()).collect();
// "cargo kani setup" comes in as "cargo-kani kani setup"
// "cargo-kani setup" comes in as "cargo-kani setup"
match &args_ez[..] {
&[_, Some("setup"), Some("--use-local-bundle"), _]
| &[_, Some("kani"), Some("setup"), Some("--use-local-bundle"), _] => {
// Grab it from args, so it can be non-utf-8
setup::setup(Some(args[3].clone()))
} else {
setup::setup(None)
}
} else {
fail_if_in_dev_environment()?;
if !setup::appears_setup() {
setup::setup(None)?;
&[_, Some("setup")] | &[_, Some("kani"), Some("setup")] => setup::setup(None),
_ => {
fail_if_in_dev_environment()?;
if !setup::appears_setup() {
setup::setup(None)?;
}
exec(bin)
}
exec(bin)
}
}

Expand Down

0 comments on commit 49f4b33

Please sign in to comment.