Skip to content

Commit bffa882

Browse files
committed
parse: fast-path help choice checks before error formatting
1 parent a2adae4 commit bffa882

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

lib/src/parse.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,19 @@ fn validate_choices(
740740
choices: Option<&SpecChoices>,
741741
custom_env: Option<&HashMap<String, String>>,
742742
) -> miette::Result<bool> {
743+
if is_help_arg(spec, value)
744+
&& choices.is_some_and(|choices| {
745+
!choices
746+
.values_with_env(custom_env)
747+
.iter()
748+
.any(|choice| choice == value)
749+
})
750+
{
751+
errors.push(render_help_err(spec, cmd, value.len() > 2));
752+
return Ok(true);
753+
}
754+
743755
if let Some(err) = choice_error(target, value, choices, custom_env) {
744-
if is_help_arg(spec, value) {
745-
errors.push(render_help_err(spec, cmd, value.len() > 2));
746-
return Ok(true);
747-
}
748756
bail!("{err}");
749757
}
750758
Ok(false)

0 commit comments

Comments
 (0)