diff options
author | Pietro Albini <pietro@pietroalbini.org> | 2020-12-10 14:10:30 +0100 |
---|---|---|
committer | Pietro Albini <pietro@pietroalbini.org> | 2020-12-10 16:25:24 +0100 |
commit | bb072fe8e77e0533d256a47a0e36d001d6fb18e5 (patch) | |
tree | 823050c16d1f9cd6ea987ab9a6fd84d2f574bc35 | |
parent | d66f476b4d5e7fdf1ec215c9ac16c923dc292324 (diff) | |
download | rust-installer-bb072fe8e77e0533d256a47a0e36d001d6fb18e5.tar.gz |
main: allow fallible conversions during CLI parsing
-rw-r--r-- | src/combiner.rs | 4 | ||||
-rw-r--r-- | src/generator.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 7 | ||||
-rw-r--r-- | src/util.rs | 4 |
4 files changed, 12 insertions, 7 deletions
diff --git a/src/combiner.rs b/src/combiner.rs index 9cdd2df..653b120 100644 --- a/src/combiner.rs +++ b/src/combiner.rs @@ -121,7 +121,7 @@ impl Combiner { .rel_manifest_dir(self.rel_manifest_dir) .success_message(self.success_message) .legacy_manifest_dirs(self.legacy_manifest_dirs) - .output_script(path_to_str(&output_script)?); + .output_script(path_to_str(&output_script)?.into()); scripter.run()?; // Make the tarballs. @@ -131,7 +131,7 @@ impl Combiner { tarballer .work_dir(self.work_dir) .input(self.package_name) - .output(path_to_str(&output)?); + .output(path_to_str(&output)?.into()); tarballer.run()?; Ok(()) diff --git a/src/generator.rs b/src/generator.rs index ecf73ca..99ba5f1 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -85,7 +85,7 @@ impl Generator { .rel_manifest_dir(self.rel_manifest_dir) .success_message(self.success_message) .legacy_manifest_dirs(self.legacy_manifest_dirs) - .output_script(path_to_str(&output_script)?); + .output_script(path_to_str(&output_script)?.into()); scripter.run()?; // Make the tarballs @@ -95,7 +95,7 @@ impl Generator { tarballer .work_dir(self.work_dir) .input(self.package_name) - .output(path_to_str(&output)?); + .output(path_to_str(&output)?.into()); tarballer.run()?; Ok(()) diff --git a/src/main.rs b/src/main.rs index 8b5f1e1..9615c9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use anyhow::{Context, Result}; use clap::{App, ArgMatches}; +use std::convert::TryInto; fn main() -> Result<()> { let yaml = clap::load_yaml!("main.yml"); @@ -19,7 +20,11 @@ macro_rules! parse( ($matches:expr => $type:ty { $( $option:tt => $setter:ident, )* }) => { { let mut command: $type = Default::default(); - $( $matches.value_of($option).map(|s| command.$setter(s)); )* + $( + if let Some(val) = $matches.value_of($option) { + command.$setter(val.try_into()?); + } + )* command } } diff --git a/src/util.rs b/src/util.rs index 3ddcfc6..078ceb3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -142,8 +142,8 @@ macro_rules! actor { impl $name { $( $( #[ $field_attr ] )+ - pub fn $field<T: Into<$type>>(&mut self, value: T) -> &mut Self { - self.$field = value.into(); + pub fn $field(&mut self, value: $type) -> &mut Self { + self.$field = value; self })+ } |