Skip to content

Commit

Permalink
do not require value_hint when none of the arguments use it
Browse files Browse the repository at this point in the history
  • Loading branch information
tertsdiepraam committed Dec 13, 2023
1 parent 42fbefa commit 9f0a0c0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions derive/src/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ pub fn complete(args: &[Argument], file: &Option<String>) -> TokenStream {
continue;
}

// If none of the flags take an argument, we won't need ValueHint
// based on that type. So we should not attempt to call `value_hint`
// on it.
let any_flag_takes_argument =
short.iter().any(|f| f.value != Value::No) && long.iter().any(|f| f.value != Value::No);

let short: Vec<_> = short
.iter()
.map(|Flag { flag, value }| {
Expand Down Expand Up @@ -69,10 +75,9 @@ pub fn complete(args: &[Argument], file: &Option<String>) -> TokenStream {
})
.collect();

let hint = if let Some(ty) = field {
quote!(Some(<#ty>::value_hint()))
} else {
quote!(None)
let hint = match (field, any_flag_takes_argument) {
(Some(ty), true) => quote!(Some(<#ty>::value_hint())),
_ => quote!(None),
};

arg_specs.push(quote!(
Expand Down

0 comments on commit 9f0a0c0

Please sign in to comment.