diff --git a/src/lib.rs b/src/lib.rs index ae16a6a..9dc662a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -445,7 +445,8 @@ pub fn parse_positional( ) -> Result<(), String> { let (slot, name) = positional; slot.fill_slot(arg).map_err(|s| { - ["Error parsing positional argument '", name, "' with value '", arg, ": ", &s].concat() + ["Error parsing positional argument '", name, "' with value '", arg, "': ", &s, "\n"] + .concat() }) } diff --git a/tests/lib.rs b/tests/lib.rs index 428015c..b27f3ef 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -206,6 +206,28 @@ fn assert_error(args: &[&str], err_msg: &str) { e.status.expect_err("error had a positive status"); } +mod options { + use super::*; + + #[derive(argh::FromArgs, Debug, PartialEq)] + /// Woot + struct Parsed { + #[argh(option, short = 'n')] + /// fooey + n: usize, + } + + #[test] + fn parsed() { + assert_output(&["-n", "5"], Parsed { n: 5 }); + assert_error::( + &["-n", "x"], + r###"Error parsing option '-n' with value 'x': invalid digit found in string +"###, + ); + } +} + mod positional { use super::*; @@ -304,6 +326,24 @@ Options: ); } + #[derive(argh::FromArgs, Debug, PartialEq)] + /// Woot + struct Parsed { + #[argh(positional)] + /// fooey + n: usize, + } + + #[test] + fn parsed() { + assert_output(&["5"], Parsed { n: 5 }); + assert_error::( + &["x"], + r###"Error parsing positional argument 'n' with value 'x': invalid digit found in string +"###, + ); + } + #[derive(FromArgs, Debug, PartialEq)] /// Woot struct WithOption {