From d48af047ddae30c8b57a138c6eeac258e1fd18dd Mon Sep 17 00:00:00 2001 From: Philipp Polterauer Date: Wed, 17 Jan 2024 19:03:16 +0100 Subject: [PATCH] fixed issue in case of no default-run --- src/main.rs | 34 ++++++---------------------------- tests/testpackage/Cargo.toml | 1 - 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6bb4f8c..71dc36e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,39 +109,17 @@ fn main() { std::process::exit(1); } // if length equal to one then we use it - let def_binary_name = if binaries.len() == 1 { - binaries.first().unwrap().name.clone().unwrap() - } else { - let name = manifest - .package - .expect("no package section") - .default_run - .expect("no default-run specified"); - - // we look for the binary with the correct name and error if we can't find it - if let Some(binary) = binaries.iter().find_map(|s| { - if let Some(n) = &s.name { - if n == &name { - s.name.clone() - } else { - None - } - } else { - None - } - }) { - binary - } else { - println!("did not find binary '{}'", name); - std::process::exit(1); - } - }; + let def_binary_name = manifest + .package + .expect("no package section") + .default_run + .unwrap_or(binaries.first().and_then(|s| s.name.clone()).expect("no binaries in the package")); // parse additional arguments from the command line let args = std::env::args().collect::>(); let args: Vec<&str> = args.iter().map(|s| s.as_str()).collect(); - // if args contains -- we split into to arg blocks + // if args contains -- we split into two arg blocks let (add_build_args, bin_args) = { let mut split = args.split(|&s| s == "--"); let a = split.next().unwrap().to_owned(); diff --git a/tests/testpackage/Cargo.toml b/tests/testpackage/Cargo.toml index 7aabf01..3882858 100644 --- a/tests/testpackage/Cargo.toml +++ b/tests/testpackage/Cargo.toml @@ -2,7 +2,6 @@ name = "testpackage" version = "0.1.0" edition = "2021" -default-run = "main" publish = false [[bin]]