Skip to content

Commit 1429d65

Browse files
committed
Ignore choices if option not supplied
1 parent 52c75e8 commit 1429d65

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

mask/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn get_command_options(mut cmd: Command, matches: &ArgMatches) -> Command {
198198
.unwrap()
199199
.to_string();
200200

201-
if !flag.choices.is_empty() {
201+
if !flag.choices.is_empty() && raw_value != "" {
202202
if !flag.choices.iter().any(|choice| choice == &raw_value) {
203203
eprintln!(
204204
"{} flag `{}` expects one of {:?}",

mask/tests/arguments_and_flags_test.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,38 @@ Write-Output "Value: $in"
212212
.success();
213213
}
214214

215+
#[test]
216+
fn ignores_the_option_if_not_supplied() {
217+
let (_temp, maskfile_path) = common::maskfile(
218+
r#"
219+
## color
220+
221+
**OPTIONS**
222+
* val
223+
* flags: --val
224+
* type: string
225+
* choices: RED, BLUE, GREEN
226+
227+
```bash
228+
echo "Value: $val;"
229+
```
230+
231+
```powershell
232+
param (
233+
$in = $env:val
234+
)
235+
Write-Output "Value: $in;"
236+
```
237+
"#,
238+
);
239+
240+
common::run_mask(&maskfile_path)
241+
.cli("color")
242+
.assert()
243+
.stdout(contains("Value: ;"))
244+
.success();
245+
}
246+
215247
#[test]
216248
fn out_of_choices() {
217249
let (_temp, maskfile_path) = common::maskfile(

0 commit comments

Comments
 (0)