Skip to content

Commit

Permalink
Ignore choices if option not supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdeichert committed Oct 13, 2024
1 parent 52c75e8 commit 1429d65
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn get_command_options(mut cmd: Command, matches: &ArgMatches) -> Command {
.unwrap()
.to_string();

if !flag.choices.is_empty() {
if !flag.choices.is_empty() && raw_value != "" {
if !flag.choices.iter().any(|choice| choice == &raw_value) {
eprintln!(
"{} flag `{}` expects one of {:?}",
Expand Down
32 changes: 32 additions & 0 deletions mask/tests/arguments_and_flags_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,38 @@ Write-Output "Value: $in"
.success();
}

#[test]
fn ignores_the_option_if_not_supplied() {
let (_temp, maskfile_path) = common::maskfile(
r#"
## color
**OPTIONS**
* val
* flags: --val
* type: string
* choices: RED, BLUE, GREEN
```bash
echo "Value: $val;"
```
```powershell
param (
$in = $env:val
)
Write-Output "Value: $in;"
```
"#,
);

common::run_mask(&maskfile_path)
.cli("color")
.assert()
.stdout(contains("Value: ;"))
.success();
}

#[test]
fn out_of_choices() {
let (_temp, maskfile_path) = common::maskfile(
Expand Down

0 comments on commit 1429d65

Please sign in to comment.