mirror of
https://github.com/topjohnwu/argh.git
synced 2024-11-23 19:59:43 +00:00
Fix quoting in errors when parsing arguments
This closes quotes in error messages when parsing arguments. Test: Added tests to make sure the error message when parsing arguments is as expected, as well as added a test to check parsing options. Closes #52
This commit is contained in:
parent
f3da6ae16c
commit
c728c85810
@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
40
tests/lib.rs
40
tests/lib.rs
@ -206,6 +206,28 @@ fn assert_error<T: FromArgs + Debug>(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::<Parsed>(
|
||||
&["-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::<Parsed>(
|
||||
&["x"],
|
||||
r###"Error parsing positional argument 'n' with value 'x': invalid digit found in string
|
||||
"###,
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(FromArgs, Debug, PartialEq)]
|
||||
/// Woot
|
||||
struct WithOption {
|
||||
|
Loading…
Reference in New Issue
Block a user