Skip to content

Commit

Permalink
fix(flagset): recognize single dash as a positional arg (#13)
Browse files Browse the repository at this point in the history
* test(flagset): add case for single dash position arg

* fix(flagset): recognize single dash as positional arg
  • Loading branch information
Zaba505 authored Sep 13, 2020
1 parent 6346d87 commit ec0a5a2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl FlagSet {

let mut av = args
.into_iter()
.flat_map(|arg| arg.chars().chain(" ".chars()))
.flat_map(|arg| arg.trim_matches(' ').chars().chain(" ".chars()))
.peekable();

loop {
Expand All @@ -344,7 +344,7 @@ impl FlagSet {
'-' => {
av.next();
let arg = av.peek();
if arg.is_none() {
if arg.is_none() || *arg.unwrap() == ' ' {
av.next();
self.args.push("-".to_string());
return Ok(());
Expand Down Expand Up @@ -974,6 +974,19 @@ mod tests {
assert_eq!(args[1], "world");
}

#[test]
fn parse_single_dash_stdin() {
let mut flags = FlagSet::new("test");

if let Err(err) = flags.parse(vec!["-"]) {
panic!(err);
}

let args = flags.args();
assert_eq!(args.len(), 1);
assert_eq!(args[0], "-");
}

#[test]
fn parse_terminate_flags() {
let mut flags = FlagSet::new("test");
Expand Down

0 comments on commit ec0a5a2

Please sign in to comment.