Skip to content

Commit

Permalink
docs(lex): Make a determination on to_long_stdio
Browse files Browse the repository at this point in the history
This tempts me to drop our design philosophy but I want to give it more
time.
  • Loading branch information
epage committed Apr 15, 2022
1 parent 88603f6 commit 87226e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions clap_lex/src/lib.rs
Expand Up @@ -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("--")?;
Expand Down
9 changes: 4 additions & 5 deletions 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]
Expand Down

0 comments on commit 87226e4

Please sign in to comment.