Debian Codegraph @

debian/rust-vendor/clap_complete/src/engine/complete.rs

raw
1 use std::ffi::OsStr;
2 use std::ffi::OsString;
3
4 use clap_lex::OsStrExt as _;
5
6 use super::ArgValueCandidates;
7 use super::ArgValueCompleter;
8 use super::CompletionCandidate;
9 use super::SubcommandCandidates;
10 use super::ValueCandidates;
11 use super::custom::complete_path;
12 use super::custom::possible_value_candidates;
13
14 /// Complete the given command, shell-agnostic
15 pub fn complete(
16 cmd: &mut clap::Command,
17 args: Vec<OsString>,
18 arg_index: usize,
19 current_dir: Option<&std::path::Path>,
20 ) -> Result<Vec<CompletionCandidate>, std::io::Error> {
21 debug!("complete: args={args:?}, arg_index={arg_index:?}, current_dir={current_dir:?}");
22 cmd.build();
23
24 let raw_args = clap_lex::RawArgs::new(args);
25 let mut cursor = raw_args.cursor();
26 let mut target_cursor = raw_args.cursor();
27 raw_args.seek(
28 &mut target_cursor,
29 clap_lex::SeekFrom::Start(arg_index as u64),
30 );
31 // As we loop, `cursor` will always be pointing to the next item
32 raw_args.next_os(&mut target_cursor);
33 debug!("complete: target_cursor={target_cursor:?}");
34
35 // TODO: Multicall support
36 if !cmd.is_no_binary_name_set() {
37 raw_args.next_os(&mut cursor);
38 }
39
40 let mut current_cmd = &*cmd;
41 let mut pos_index = 1;
42 let mut is_escaped = false;
43 let mut next_state = ParseState::ValueDone;
44 while let Some(arg) = raw_args.next(&mut cursor) {
45 let current_state = next_state;
46 next_state = ParseState::ValueDone;
47 debug!(
48 "complete::next: arg={:?}, current_state={current_state:?}, cursor={cursor:?}",
49 arg.to_value_os(),
50 );
51 if cursor == target_cursor {
52 return complete_arg(
53 &arg,
54 current_cmd,
55 current_dir,
56 pos_index,
57 is_escaped,
58 current_state,
59 );
60 }
61
62 if let Ok(value) = arg.to_value() {
63 if let Some(next_cmd) = current_cmd.find_subcommand(value) {
64 current_cmd = next_cmd;
65 pos_index = 1;
66 continue;
67 }
68 }
69
70 if is_escaped {
71 (next_state, pos_index) =
72 parse_positional(current_cmd, pos_index, is_escaped, current_state);
73 } else if arg.is_escape() {
74 is_escaped = true;
75 } else if opt_allows_hyphen(&current_state, &arg) {
76 match current_state {
77 ParseState::Opt((opt, count)) => next_state = parse_opt_value(opt, count),
78 _ => unreachable!("else branch is only reachable in Opt state"),
79 }
80 } else if let Some((flag, value)) = arg.to_long() {
81 if let Ok(flag) = flag {
82 let opt = current_cmd.get_arguments().find(|a| {
83 let longs = a.get_long_and_visible_aliases();
84 let is_find = longs.map(|v| {
85 let mut iter = v.into_iter();
86 let s = iter.find(|s| *s == flag);
87 s.is_some()
88 });
89 is_find.unwrap_or(false)
90 });
91
92 if let Some(opt) = opt {
93 if opt.get_num_args().expect("built").takes_values() && value.is_none() {
94 next_state = ParseState::Opt((opt, 1));
95 };
96 } else if pos_allows_hyphen(current_cmd, pos_index) {
97 (next_state, pos_index) =
98 parse_positional(current_cmd, pos_index, is_escaped, current_state);
99 }
100 }
101 } else if let Some(short) = arg.to_short() {
102 let (_, takes_value_opt, mut short) = parse_shortflags(current_cmd, short);
103 if let Some(opt) = takes_value_opt {
104 if short.next_value_os().is_none() {
105 next_state = ParseState::Opt((opt, 1));
106 }
107 } else if pos_allows_hyphen(current_cmd, pos_index) {
108 (next_state, pos_index) =
109 parse_positional(current_cmd, pos_index, is_escaped, current_state);
110 }
111 } else {
112 match current_state {
113 ParseState::ValueDone | ParseState::Pos(..) => {
114 (next_state, pos_index) =
115 parse_positional(current_cmd, pos_index, is_escaped, current_state);
116 }
117 ParseState::Opt((opt, count)) => next_state = parse_opt_value(opt, count),
118 }
119 }
120 }
121
122 Err(std::io::Error::other("no completion generated"))
123 }
124
125 #[derive(Debug, PartialEq, Eq, Clone)]
126 enum ParseState<'a> {
127 /// Parsing a value done, there is no state to record.
128 ValueDone,
129
130 /// Parsing a positional argument after `--`. `Pos(pos_index`, `takes_num_args`)
131 Pos((usize, usize)),
132
133 /// Parsing a optional flag argument
134 Opt((&'a clap::Arg, usize)),
135 }
136
137 fn complete_arg(
138 arg: &clap_lex::ParsedArg<'_>,
139 cmd: &clap::Command,
140 current_dir: Option<&std::path::Path>,
141 pos_index: usize,
142 is_escaped: bool,
143 state: ParseState<'_>,
144 ) -> Result<Vec<CompletionCandidate>, std::io::Error> {
145 debug!(
146 "complete_arg: arg={:?}, cmd={:?}, current_dir={:?}, pos_index={:?}, state={:?}",
147 arg,
148 cmd.get_name(),
149 current_dir,
150 pos_index,
151 state
152 );
153 let mut completions = Vec::<CompletionCandidate>::new();
154
155 match state {
156 ParseState::ValueDone => {
157 if let Ok(value) = arg.to_value() {
158 completions.extend(complete_subcommand(value, cmd));
159 }
160
161 if let Some(positional) = cmd
162 .get_positionals()
163 .find(|p| p.get_index() == Some(pos_index))
164 {
165 completions.extend(complete_arg_value(
166 arg.to_value(),
167 positional,
168 current_dir,
169 0,
170 ));
171 }
172 if !is_escaped {
173 completions.extend(complete_option(arg, cmd, current_dir));
174 }
175 }
176 ParseState::Pos((_, num_arg)) => {
177 if let Some(positional) = cmd
178 .get_positionals()
179 .find(|p| p.get_index() == Some(pos_index))
180 {
181 completions.extend(complete_arg_value(
182 arg.to_value(),
183 positional,
184 current_dir,
185 num_arg.saturating_sub(1),
186 ));
187 if !is_escaped
188 && positional
189 .get_num_args()
190 .is_some_and(|num_args| num_arg >= num_args.min_values())
191 {
192 completions.extend(complete_option(arg, cmd, current_dir));
193 }
194 }
195 }
196 ParseState::Opt((opt, count)) => {
197 completions.extend(complete_arg_value(
198 arg.to_value(),
199 opt,
200 current_dir,
201 count.saturating_sub(1),
202 ));
203 let min = opt.get_num_args().map(|r| r.min_values()).unwrap_or(0);
204 if count > min {
205 // Also complete this raw_arg as a positional argument, flags, options and subcommand.
206 completions.extend(complete_arg(
207 arg,
208 cmd,
209 current_dir,
210 pos_index,
211 is_escaped,
212 ParseState::ValueDone,
213 )?);
214 }
215 }
216 }
217 if completions.iter().any(|a| !a.is_hide_set()) {
218 completions.retain(|a| !a.is_hide_set());
219 }
220 let mut seen_ids = std::collections::HashSet::new();
221 completions.retain(move |a| {
222 if let Some(id) = a.get_id().cloned() {
223 seen_ids.insert(id)
224 } else {
225 true
226 }
227 });
228
229 let mut tags = Vec::new();
230 for candidate in &completions {
231 let tag = candidate.get_tag().cloned();
232 if !tags.contains(&tag) {
233 tags.push(tag);
234 }
235 }
236 completions.sort_by_key(|c| {
237 (
238 tags.iter().position(|t| c.get_tag() == t.as_ref()),
239 c.get_display_order(),
240 )
241 });
242
243 Ok(completions)
244 }
245
246 fn complete_option(
247 arg: &clap_lex::ParsedArg<'_>,
248 cmd: &clap::Command,
249 current_dir: Option<&std::path::Path>,
250 ) -> Vec<CompletionCandidate> {
251 debug!("complete_option: arg={arg:?}, current_dir={current_dir:?}");
252 let mut completions = Vec::<CompletionCandidate>::new();
253 if arg.is_empty() {
254 completions.extend(longs_and_visible_aliases(cmd));
255 completions.extend(hidden_longs_aliases(cmd));
256
257 let dash_or_arg = if arg.is_empty() {
258 "-".into()
259 } else {
260 arg.to_value_os().to_string_lossy()
261 };
262 completions.extend(
263 shorts_and_visible_aliases(cmd)
264 .into_iter()
265 .map(|comp| comp.add_prefix(dash_or_arg.to_string())),
266 );
267 } else if arg.is_stdio() {
268 // HACK: Assuming knowledge of is_stdio
269 let dash_or_arg = if arg.is_empty() {
270 "-".into()
271 } else {
272 arg.to_value_os().to_string_lossy()
273 };
274 completions.extend(
275 shorts_and_visible_aliases(cmd)
276 .into_iter()
277 .map(|comp| comp.add_prefix(dash_or_arg.to_string())),
278 );
279
280 completions.extend(longs_and_visible_aliases(cmd));
281 completions.extend(hidden_longs_aliases(cmd));
282 } else if arg.is_escape() {
283 // HACK: Assuming knowledge of is_escape
284 completions.extend(longs_and_visible_aliases(cmd));
285 completions.extend(hidden_longs_aliases(cmd));
286 } else if let Some((flag, value)) = arg.to_long() {
287 if let Ok(flag) = flag {
288 if let Some(value) = value {
289 if let Some(arg) = cmd.get_arguments().find(|a| a.get_long() == Some(flag)) {
290 completions.extend(
291 complete_arg_value(value.to_str().ok_or(value), arg, current_dir, 0)
292 .into_iter()
293 .map(|comp| comp.add_prefix(format!("--{flag}="))),
294 );
295 }
296 } else {
297 completions.extend(
298 longs_and_visible_aliases(cmd)
299 .into_iter()
300 .filter(|comp| comp.get_value().starts_with(format!("--{flag}").as_str())),
301 );
302 completions.extend(
303 hidden_longs_aliases(cmd)
304 .into_iter()
305 .filter(|comp| comp.get_value().starts_with(format!("--{flag}").as_str())),
306 );
307 }
308 }
309 } else if let Some(short) = arg.to_short() {
310 if !short.is_negative_number() {
311 // Find the first takes_values option.
312 let (leading_flags, takes_value_opt, mut short) = parse_shortflags(cmd, short);
313
314 // Clone `short` to `peek_short` to peek whether the next flag is a `=`.
315 if let Some(opt) = takes_value_opt {
316 let mut peek_short = short.clone();
317 let has_equal = if let Some(Ok('=')) = peek_short.next_flag() {
318 short.next_flag();
319 true
320 } else {
321 false
322 };
323
324 let value = short.next_value_os().unwrap_or(OsStr::new(""));
325 completions.extend(
326 complete_arg_value(value.to_str().ok_or(value), opt, current_dir, 0)
327 .into_iter()
328 .map(|comp| {
329 let sep = if has_equal { "=" } else { "" };
330 comp.add_prefix(format!("-{leading_flags}{sep}"))
331 }),
332 );
333 } else {
334 completions.extend(
335 shorts_and_visible_aliases(cmd)
336 .into_iter()
337 .map(|comp| comp.add_prefix(format!("-{leading_flags}"))),
338 );
339 }
340 }
341 }
342 debug!("complete_option: completions={completions:?}");
343 completions
344 }
345
346 fn complete_arg_value(
347 value: Result<&str, &OsStr>,
348 arg: &clap::Arg,
349 current_dir: Option<&std::path::Path>,
350 arg_index: usize,
351 ) -> Vec<CompletionCandidate> {
352 let mut values = Vec::new();
353 debug!("complete_arg_value: arg={arg:?}, value={value:?}, arg_index={arg_index:?}");
354
355 let (prefix, value) =
356 rsplit_delimiter(value, arg.get_value_delimiter()).unwrap_or((None, value));
357
358 let value_os = match value {
359 Ok(value) => OsStr::new(value),
360 Err(value_os) => value_os,
361 };
362
363 if let Some(completer) = arg.get::<ArgValueCompleter>() {
364 values.extend(completer.complete_at(arg_index, value_os));
365 } else if let Some(completer) = arg.get::<ArgValueCandidates>() {
366 values.extend(complete_value_candidates(
367 value_os,
368 completer.value_candidates(),
369 ));
370 } else if let Some(possible_values) = possible_values(arg) {
371 if let Ok(value) = value {
372 values.extend(complete_candidates_str(
373 value,
374 possible_value_candidates(possible_values),
375 ));
376 }
377 } else {
378 match arg.get_value_hint() {
379 clap::ValueHint::Unknown | clap::ValueHint::Other => {
380 // Should not complete
381 }
382 clap::ValueHint::AnyPath => {
383 values.extend(complete_path(value_os, current_dir, &|_| true));
384 }
385 clap::ValueHint::FilePath => {
386 values.extend(complete_path(value_os, current_dir, &|p| p.is_file()));
387 }
388 clap::ValueHint::DirPath => {
389 values.extend(complete_path(value_os, current_dir, &|p| p.is_dir()));
390 }
391 clap::ValueHint::ExecutablePath => {
392 use is_executable::IsExecutable;
393 values.extend(complete_path(value_os, current_dir, &|p| p.is_executable()));
394 }
395 clap::ValueHint::CommandName
396 | clap::ValueHint::CommandString
397 | clap::ValueHint::CommandWithArguments
398 | clap::ValueHint::Username
399 | clap::ValueHint::Hostname
400 | clap::ValueHint::Url
401 | clap::ValueHint::EmailAddress => {
402 // No completion implementation
403 }
404 _ => {
405 // Safe-ish fallback
406 values.extend(complete_path(value_os, current_dir, &|_| true));
407 }
408 }
409
410 values.sort();
411 }
412
413 if let Some(prefix) = prefix {
414 values = values
415 .into_iter()
416 .map(|comp| comp.add_prefix(prefix))
417 .collect();
418 }
419 values = values
420 .into_iter()
421 .map(|comp| {
422 if comp.get_tag().is_some() {
423 comp
424 } else {
425 comp.tag(Some(arg.to_string().into()))
426 }
427 })
428 .collect();
429
430 debug!("complete_arg_value: values={values:?}");
431 values
432 }
433
434 fn rsplit_delimiter<'s, 'o>(
435 value: Result<&'s str, &'o OsStr>,
436 delimiter: Option<char>,
437 ) -> Option<(Option<&'s str>, Result<&'s str, &'o OsStr>)> {
438 let delimiter = delimiter?;
439 let value = value.ok()?;
440 let pos = value.rfind(delimiter)?;
441 let (prefix, value) = value.split_at(pos + delimiter.len_utf8());
442 Some((Some(prefix), Ok(value)))
443 }
444
445 fn complete_value_candidates(
446 value: &OsStr,
447 completer: &dyn ValueCandidates,
448 ) -> Vec<CompletionCandidate> {
449 debug!("complete_value_candidates: value={value:?}");
450
451 let mut values = completer.candidates();
452 values.retain(|comp| comp.get_value().starts_with(&value.to_string_lossy()));
453 values
454 }
455
456 fn complete_candidates_str(
457 value: &str,
458 mut values: Vec<CompletionCandidate>,
459 ) -> Vec<CompletionCandidate> {
460 debug!("complete_candidates_str: value={value:?}");
461
462 values.retain(|comp| comp.get_value().starts_with(value));
463 values
464 }
465
466 fn complete_value_candidates_str(
467 value: &str,
468 completer: &dyn ValueCandidates,
469 ) -> Vec<CompletionCandidate> {
470 debug!("complete_value_candidates_str: value={value:?}");
471
472 complete_candidates_str(value, completer.candidates())
473 }
474
475 fn complete_subcommand(value: &str, cmd: &clap::Command) -> Vec<CompletionCandidate> {
476 debug!(
477 "complete_subcommand: cmd={:?}, value={:?}",
478 cmd.get_name(),
479 value
480 );
481
482 let mut scs: Vec<CompletionCandidate> = subcommands(cmd)
483 .into_iter()
484 .filter(|x| x.get_value().starts_with(value))
485 .collect();
486 if cmd.is_allow_external_subcommands_set() {
487 let external_completer = cmd.get::<SubcommandCandidates>();
488 if let Some(completer) = external_completer {
489 scs.extend(complete_value_candidates_str(
490 value,
491 completer.value_candidates(),
492 ));
493 }
494 }
495
496 scs.sort();
497 scs.dedup();
498 scs
499 }
500
501 /// Gets all the long options, their visible aliases and flags of a [`clap::Command`] with formatted `--` prefix.
502 /// Includes `help` and `version` depending on the [`clap::Command`] settings.
503 fn longs_and_visible_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
504 debug!("longs: name={}", p.get_name());
505
506 p.get_arguments()
507 .filter_map(|a| {
508 a.get_long_and_visible_aliases().map(|longs| {
509 longs
510 .into_iter()
511 .map(|s| populate_arg_candidate(CompletionCandidate::new(format!("--{s}")), a))
512 })
513 })
514 .flatten()
515 .collect()
516 }
517
518 /// Gets all the long hidden aliases and flags of a [`clap::Command`].
519 fn hidden_longs_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
520 debug!("longs: name={}", p.get_name());
521
522 p.get_arguments()
523 .filter_map(|a| {
524 a.get_aliases().map(|longs| {
525 longs.into_iter().map(|s| {
526 populate_arg_candidate(CompletionCandidate::new(format!("--{s}")), a).hide(true)
527 })
528 })
529 })
530 .flatten()
531 .collect()
532 }
533
534 /// Gets all the short options, their visible aliases and flags of a [`clap::Command`].
535 /// Includes `h` and `V` depending on the [`clap::Command`] settings.
536 fn shorts_and_visible_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
537 debug!("shorts: name={}", p.get_name());
538
539 p.get_arguments()
540 .filter_map(|a| {
541 a.get_short_and_visible_aliases().map(|shorts| {
542 shorts.into_iter().map(|s| {
543 populate_arg_candidate(CompletionCandidate::new(s.to_string()), a).help(
544 a.get_help()
545 .cloned()
546 .or_else(|| a.get_long().map(|long| format!("--{long}").into())),
547 )
548 })
549 })
550 })
551 .flatten()
552 .collect()
553 }
554
555 fn populate_arg_candidate(candidate: CompletionCandidate, arg: &clap::Arg) -> CompletionCandidate {
556 candidate
557 .help(arg.get_help().cloned())
558 .id(Some(format!("arg::{}", arg.get_id())))
559 .tag(Some(
560 arg.get_help_heading()
561 .unwrap_or("Options")
562 .to_owned()
563 .into(),
564 ))
565 .display_order(Some(arg.get_display_order()))
566 .hide(arg.is_hide_set())
567 }
568
569 /// Get the possible values for completion
570 fn possible_values(
571 a: &clap::Arg,
572 ) -> Option<Box<dyn Iterator<Item = clap::builder::PossibleValue> + '_>> {
573 if !a.get_num_args().expect("built").takes_values() {
574 None
575 } else {
576 a.get_value_parser().possible_values()
577 }
578 }
579
580 /// Gets subcommands of [`clap::Command`] in the form of `("name", "bin_name")`.
581 ///
582 /// Subcommand `rustup toolchain install` would be converted to
583 /// `("install", "rustup toolchain install")`.
584 fn subcommands(p: &clap::Command) -> Vec<CompletionCandidate> {
585 debug!("subcommands: name={}", p.get_name());
586 debug!("subcommands: Has subcommands...{:?}", p.has_subcommands());
587 p.get_subcommands()
588 .flat_map(|sc| {
589 sc.get_name_and_visible_aliases()
590 .into_iter()
591 .map(|s| populate_command_candidate(CompletionCandidate::new(s.to_owned()), p, sc))
592 .chain(sc.get_aliases().map(|s| {
593 populate_command_candidate(CompletionCandidate::new(s.to_owned()), p, sc)
594 .hide(true)
595 }))
596 })
597 .collect()
598 }
599
600 fn populate_command_candidate(
601 candidate: CompletionCandidate,
602 cmd: &clap::Command,
603 subcommand: &clap::Command,
604 ) -> CompletionCandidate {
605 candidate
606 .help(subcommand.get_about().cloned())
607 .id(Some(format!("command::{}", subcommand.get_name())))
608 .tag(Some(
609 cmd.get_subcommand_help_heading()
610 .unwrap_or("Commands")
611 .to_owned()
612 .into(),
613 ))
614 .display_order(Some(subcommand.get_display_order()))
615 .hide(subcommand.is_hide_set())
616 }
617
618 /// Parse the short flags and find the first `takes_values` option.
619 fn parse_shortflags<'c, 's>(
620 cmd: &'c clap::Command,
621 mut short: clap_lex::ShortFlags<'s>,
622 ) -> (String, Option<&'c clap::Arg>, clap_lex::ShortFlags<'s>) {
623 let takes_value_opt;
624 let mut leading_flags = String::new();
625 // Find the first takes_values option.
626 loop {
627 match short.next_flag() {
628 Some(Ok(opt)) => {
629 leading_flags.push(opt);
630 let opt = cmd.get_arguments().find(|a| {
631 let shorts = a.get_short_and_visible_aliases();
632 let is_find = shorts.map(|v| {
633 let mut iter = v.into_iter();
634 let c = iter.find(|c| *c == opt);
635 c.is_some()
636 });
637 is_find.unwrap_or(false)
638 });
639 if opt
640 .map(|o| o.get_num_args().expect("built").takes_values())
641 .unwrap_or(false)
642 {
643 takes_value_opt = opt;
644 break;
645 }
646 }
647 Some(Err(_)) | None => {
648 takes_value_opt = None;
649 break;
650 }
651 }
652 }
653
654 (leading_flags, takes_value_opt, short)
655 }
656
657 /// Parse the positional arguments. Return the new state and the new positional index.
658 fn parse_positional<'a>(
659 cmd: &clap::Command,
660 pos_index: usize,
661 is_escaped: bool,
662 state: ParseState<'a>,
663 ) -> (ParseState<'a>, usize) {
664 let pos_arg = cmd
665 .get_positionals()
666 .find(|p| p.get_index() == Some(pos_index));
667 let num_args = pos_arg
668 .and_then(|a| a.get_num_args().map(|r| r.max_values()))
669 .unwrap_or(1);
670
671 let update_state_with_new_positional = |pos_index| -> (ParseState<'a>, usize) {
672 if num_args > 1 {
673 (ParseState::Pos((pos_index, 1)), pos_index)
674 } else {
675 if is_escaped {
676 (ParseState::Pos((pos_index, 1)), pos_index + 1)
677 } else {
678 (ParseState::ValueDone, pos_index + 1)
679 }
680 }
681 };
682 match state {
683 ParseState::ValueDone => {
684 update_state_with_new_positional(pos_index)
685 },
686 ParseState::Pos((prev_pos_index, num_arg)) => {
687 if prev_pos_index == pos_index {
688 if num_arg + 1 < num_args {
689 (ParseState::Pos((pos_index, num_arg + 1)), pos_index)
690 } else {
691 if is_escaped {
692 (ParseState::Pos((pos_index, 1)), pos_index + 1)
693 } else {
694 (ParseState::ValueDone, pos_index + 1)
695 }
696 }
697 } else {
698 update_state_with_new_positional(pos_index)
699 }
700 }
701 ParseState::Opt(..) => unreachable!(
702 "This branch won't be hit,
703 because ParseState::Opt should not be seen as a positional argument and passed to this function."
704 ),
705 }
706 }
707
708 /// Parse optional flag argument. Return new state
709 fn parse_opt_value(opt: &clap::Arg, count: usize) -> ParseState<'_> {
710 let range = opt.get_num_args().expect("built");
711 let max = range.max_values();
712 if count < max {
713 ParseState::Opt((opt, count + 1))
714 } else {
715 ParseState::ValueDone
716 }
717 }
718
719 fn pos_allows_hyphen(cmd: &clap::Command, pos_index: usize) -> bool {
720 cmd.get_positionals()
721 .find(|a| a.get_index() == Some(pos_index))
722 .map(|p| p.is_allow_hyphen_values_set())
723 .unwrap_or(false)
724 }
725
726 fn opt_allows_hyphen(state: &ParseState<'_>, arg: &clap_lex::ParsedArg<'_>) -> bool {
727 let val = arg.to_value_os();
728 if val.starts_with("-") {
729 if let ParseState::Opt((opt, _)) = state {
730 return opt.is_allow_hyphen_values_set();
731 }
732 }
733
734 false
735 }