From 87226e4545717da9fdd6daa002df508b179dac6c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 15 Apr 2022 12:46:07 -0500 Subject: [PATCH] docs(lex): Make a determination on to_long_stdio This tempts me to drop our design philosophy but I want to give it more time. --- clap_lex/src/lib.rs | 3 +++ clap_lex/tests/parsed.rs | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clap_lex/src/lib.rs b/clap_lex/src/lib.rs index 136f37d28acb..c9c8b3d70497 100644 --- a/clap_lex/src/lib.rs +++ b/clap_lex/src/lib.rs @@ -292,6 +292,9 @@ impl<'s> ParsedArg<'s> { /// Treat as a long-flag /// /// **NOTE:** May return an empty flag. Check [`ParsedArg::is_escape`] to separately detect `--`. + /// + /// **NOTE:** Will not match [`ParsedArg::is_stdio`], completion engines will need to check + /// that case. pub fn to_long(&self) -> Option<(Result<&str, &RawOsStr>, Option<&RawOsStr>)> { if let Some(raw) = self.utf8 { let remainder = raw.strip_prefix("--")?; diff --git a/clap_lex/tests/parsed.rs b/clap_lex/tests/parsed.rs index c0069de80d29..286b66a9ea23 100644 --- a/clap_lex/tests/parsed.rs +++ b/clap_lex/tests/parsed.rs @@ -1,16 +1,15 @@ +// Despite our design philosophy being to support completion generation, we aren't considering `-` +// the start of a long because there is no valid value to return. #[test] -#[should_panic] // Our design philosophy is to match X if it can be completed as X which we break here fn to_long_stdio() { let raw = clap_lex::RawArgs::from_iter(["bin", "-"]); let mut cursor = raw.cursor(); assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin"))); let next = raw.next(&mut cursor).unwrap(); - assert!(next.is_long()); + assert!(!next.is_long()); - let (key, value) = next.to_long().unwrap(); - assert_eq!(key, Ok("")); - assert_eq!(value, None); + assert_eq!(next.to_long(), None); } #[test]