Skip to content

Commit

Permalink
feat: negate
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Sep 26, 2024
1 parent 5d1b817 commit 16f754d
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ pub fn parse<'a>(spec: &'a Spec, input: &[String]) -> Result<ParseOutput<'a>, mi
.unwrap();
arr.push(true);
} else {
flags.insert(f.clone(), ParseValue::Bool(true));
let negate = f.negate.clone().unwrap_or_default();
flags.insert(f.clone(), ParseValue::Bool(w != negate));
}
continue;
}
Expand Down Expand Up @@ -272,19 +273,32 @@ mod tests {
bin: "test".to_string(),
cmd: SpecCommand {
name: "test".to_string(),
flags: vec![SpecFlag {
name: "flag".to_string(),
long: vec!["flag".to_string()],
..Default::default()
}],
flags: vec![
SpecFlag {
name: "flag".to_string(),
long: vec!["flag".to_string()],
..Default::default()
},
SpecFlag {
name: "force".to_string(),
long: vec!["force".to_string()],
negate: Some("--no-force".to_string()),
..Default::default()
},
],
..Default::default()
},
..Default::default()
};
let input = vec!["test".to_string(), "--flag".to_string()];
let input = vec![
"test".to_string(),
"--flag".to_string(),
"--no-force".to_string(),
];
let parsed = parse(&spec, &input).unwrap();
let env = parsed.as_env();
assert_eq!(env.len(), 1);
assert_eq!(env.len(), 2);
assert_eq!(env.get("usage_flag"), Some(&"true".to_string()));
assert_eq!(env.get("usage_force"), Some(&"false".to_string()));
}
}

0 comments on commit 16f754d

Please sign in to comment.