From d337a80ff5b2646c0cf44923bc4ddbaacc8eddb5 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 18:00:47 -0400 Subject: [PATCH] Use matches.value_of_t --- cli/src/lib.rs | 8 ++++---- cli/src/main.rs | 16 +++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 11469c82aa..dbeab8b027 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -669,15 +669,15 @@ impl std::fmt::Display for Target { } impl std::str::FromStr for Target { - type Err = (); + type Err = String; - fn from_str(s: &str) -> Result { - match s { + fn from_str(string: &str) -> Result { + match string { "system" => Ok(Target::System), "linux32" => Ok(Target::Linux32), "linux64" => Ok(Target::Linux64), "wasm32" => Ok(Target::Wasm32), - _ => Err(()), + _ => Err(format!("Roc does not know how to compile to {}", string)), } } } diff --git a/cli/src/main.rs b/cli/src/main.rs index 3c2c413f0b..0a21c66ed5 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -67,14 +67,7 @@ fn main() -> io::Result<()> { } } Some((CMD_BUILD, matches)) => { - use std::str::FromStr; - - let target = match matches.value_of(FLAG_TARGET) { - Some(name) => Target::from_str(name).unwrap(), - None => Target::default(), - }; - - let triple = target.to_triple(); + let target: Target = matches.value_of_t(FLAG_TARGET).unwrap_or_default(); let link_type = match ( matches.is_present(FLAG_LIB), @@ -86,7 +79,12 @@ fn main() -> io::Result<()> { (false, false) => LinkType::Executable, }; - Ok(build(matches, BuildConfig::BuildOnly, triple, link_type)?) + Ok(build( + matches, + BuildConfig::BuildOnly, + target.to_triple(), + link_type, + )?) } Some((CMD_CHECK, matches)) => { let arena = bumpalo::Bump::new();