mirror of
https://github.com/clap-rs/clap
synced 2024-09-20 14:31:58 +00:00
style: Make clippy happy
This commit is contained in:
parent
2f0d91688a
commit
15d8b3b0cd
6 changed files with 48 additions and 44 deletions
|
@ -52,7 +52,7 @@
|
||||||
//! verbosity: 0,
|
//! verbosity: 0,
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! let raw = clap_lex::RawArgs::from_iter(raw);
|
//! let raw = clap_lex::RawArgs::new(raw);
|
||||||
//! let mut cursor = raw.cursor();
|
//! let mut cursor = raw.cursor();
|
||||||
//! raw.next(&mut cursor); // Skip the bin
|
//! raw.next(&mut cursor); // Skip the bin
|
||||||
//! while let Some(arg) = raw.next(&mut cursor) {
|
//! while let Some(arg) = raw.next(&mut cursor) {
|
||||||
|
@ -124,6 +124,8 @@ pub struct RawArgs {
|
||||||
impl RawArgs {
|
impl RawArgs {
|
||||||
//// Create an argument list to parse
|
//// Create an argument list to parse
|
||||||
///
|
///
|
||||||
|
/// **NOTE:** The argument returned will be the current binary.
|
||||||
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
|
@ -136,7 +138,7 @@ impl RawArgs {
|
||||||
/// println!("{:?}", paths);
|
/// println!("{:?}", paths);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn from_args() -> Self {
|
pub fn from_args() -> Self {
|
||||||
Self::from_iter(std::env::args_os())
|
Self::new(std::env::args_os())
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Create an argument list to parse
|
//// Create an argument list to parse
|
||||||
|
@ -145,14 +147,14 @@ impl RawArgs {
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use std::path::PathBuf;
|
/// # use std::path::PathBuf;
|
||||||
/// let raw = clap_lex::RawArgs::from_iter(["bin", "foo.txt"]);
|
/// let raw = clap_lex::RawArgs::new(["bin", "foo.txt"]);
|
||||||
/// let mut cursor = raw.cursor();
|
/// let mut cursor = raw.cursor();
|
||||||
/// let _bin = raw.next_os(&mut cursor);
|
/// let _bin = raw.next_os(&mut cursor);
|
||||||
///
|
///
|
||||||
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
|
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
|
||||||
/// println!("{:?}", paths);
|
/// println!("{:?}", paths);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn from_iter(iter: impl IntoIterator<Item = impl Into<std::ffi::OsString>>) -> Self {
|
pub fn new(iter: impl IntoIterator<Item = impl Into<std::ffi::OsString>>) -> Self {
|
||||||
let iter = iter.into_iter();
|
let iter = iter.into_iter();
|
||||||
Self::from(iter)
|
Self::from(iter)
|
||||||
}
|
}
|
||||||
|
@ -163,7 +165,7 @@ impl RawArgs {
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use std::path::PathBuf;
|
/// # use std::path::PathBuf;
|
||||||
/// let raw = clap_lex::RawArgs::from_iter(["bin", "foo.txt"]);
|
/// let raw = clap_lex::RawArgs::new(["bin", "foo.txt"]);
|
||||||
/// let mut cursor = raw.cursor();
|
/// let mut cursor = raw.cursor();
|
||||||
/// let _bin = raw.next_os(&mut cursor);
|
/// let _bin = raw.next_os(&mut cursor);
|
||||||
///
|
///
|
||||||
|
@ -202,7 +204,7 @@ impl RawArgs {
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use std::path::PathBuf;
|
/// # use std::path::PathBuf;
|
||||||
/// let raw = clap_lex::RawArgs::from_iter(["bin", "foo.txt"]);
|
/// let raw = clap_lex::RawArgs::new(["bin", "foo.txt"]);
|
||||||
/// let mut cursor = raw.cursor();
|
/// let mut cursor = raw.cursor();
|
||||||
/// let _bin = raw.next_os(&mut cursor);
|
/// let _bin = raw.next_os(&mut cursor);
|
||||||
///
|
///
|
||||||
|
@ -299,7 +301,7 @@ impl<'s> ParsedArg<'s> {
|
||||||
pub fn to_long(&self) -> Option<(Result<&str, &RawOsStr>, Option<&RawOsStr>)> {
|
pub fn to_long(&self) -> Option<(Result<&str, &RawOsStr>, Option<&RawOsStr>)> {
|
||||||
if let Some(raw) = self.utf8 {
|
if let Some(raw) = self.utf8 {
|
||||||
let remainder = raw.strip_prefix("--")?;
|
let remainder = raw.strip_prefix("--")?;
|
||||||
let (flag, value) = if let Some((p0, p1)) = remainder.split_once("=") {
|
let (flag, value) = if let Some((p0, p1)) = remainder.split_once('=') {
|
||||||
(p0, Some(p1))
|
(p0, Some(p1))
|
||||||
} else {
|
} else {
|
||||||
(remainder, None)
|
(remainder, None)
|
||||||
|
@ -310,12 +312,12 @@ impl<'s> ParsedArg<'s> {
|
||||||
} else {
|
} else {
|
||||||
let raw = self.inner.as_ref();
|
let raw = self.inner.as_ref();
|
||||||
let remainder = raw.strip_prefix("--")?;
|
let remainder = raw.strip_prefix("--")?;
|
||||||
let (flag, value) = if let Some((p0, p1)) = remainder.split_once("=") {
|
let (flag, value) = if let Some((p0, p1)) = remainder.split_once('=') {
|
||||||
(p0, Some(p1))
|
(p0, Some(p1))
|
||||||
} else {
|
} else {
|
||||||
(remainder, None)
|
(remainder, None)
|
||||||
};
|
};
|
||||||
let flag = flag.to_str().ok_or_else(|| flag);
|
let flag = flag.to_str().ok_or(flag);
|
||||||
Some((flag, value))
|
Some((flag, value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,7 +365,7 @@ impl<'s> ParsedArg<'s> {
|
||||||
///
|
///
|
||||||
/// **NOTE:** May return a flag or an escape.
|
/// **NOTE:** May return a flag or an escape.
|
||||||
pub fn to_value(&self) -> Result<&str, &RawOsStr> {
|
pub fn to_value(&self) -> Result<&str, &RawOsStr> {
|
||||||
self.utf8.ok_or(self.inner.as_ref())
|
self.utf8.ok_or_else(|| self.inner.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Safely print an argument that may contain non-UTF8 content
|
/// Safely print an argument that may contain non-UTF8 content
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#[test]
|
#[test]
|
||||||
fn insert() {
|
fn insert() {
|
||||||
let mut raw = clap_lex::RawArgs::from_iter(["bin", "a", "b", "c"]);
|
let mut raw = clap_lex::RawArgs::new(["bin", "a", "b", "c"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
|
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("a")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("a")));
|
||||||
raw.insert(&mut cursor, &["1", "2", "3"]);
|
raw.insert(&cursor, &["1", "2", "3"]);
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("1")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("1")));
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("2")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("2")));
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("3")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("3")));
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// the start of a long because there is no valid value to return.
|
// the start of a long because there is no valid value to return.
|
||||||
#[test]
|
#[test]
|
||||||
fn to_long_stdio() {
|
fn to_long_stdio() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -14,7 +14,7 @@ fn to_long_stdio() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_long_escape() {
|
fn to_long_escape() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "--"]);
|
let raw = clap_lex::RawArgs::new(["bin", "--"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -28,7 +28,7 @@ fn to_long_escape() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_long_no_value() {
|
fn to_long_no_value() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "--long"]);
|
let raw = clap_lex::RawArgs::new(["bin", "--long"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -42,7 +42,7 @@ fn to_long_no_value() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_long_with_empty_value() {
|
fn to_long_with_empty_value() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "--long="]);
|
let raw = clap_lex::RawArgs::new(["bin", "--long="]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -56,7 +56,7 @@ fn to_long_with_empty_value() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_long_with_value() {
|
fn to_long_with_value() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "--long=hello"]);
|
let raw = clap_lex::RawArgs::new(["bin", "--long=hello"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -70,7 +70,7 @@ fn to_long_with_value() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_short_stdio() {
|
fn to_short_stdio() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -83,7 +83,7 @@ fn to_short_stdio() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_short_escape() {
|
fn to_short_escape() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "--"]);
|
let raw = clap_lex::RawArgs::new(["bin", "--"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -95,7 +95,7 @@ fn to_short_escape() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_short_long() {
|
fn to_short_long() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "--long"]);
|
let raw = clap_lex::RawArgs::new(["bin", "--long"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -107,7 +107,7 @@ fn to_short_long() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_short() {
|
fn to_short() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-short"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-short"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -121,7 +121,7 @@ fn to_short() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_negative_number() {
|
fn is_negative_number() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-10.0"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-10.0"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -131,7 +131,7 @@ fn is_negative_number() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_positive_number() {
|
fn is_positive_number() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "10.0"]);
|
let raw = clap_lex::RawArgs::new(["bin", "10.0"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -141,7 +141,7 @@ fn is_positive_number() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_not_number() {
|
fn is_not_number() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "--10.0"]);
|
let raw = clap_lex::RawArgs::new(["bin", "--10.0"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -151,7 +151,7 @@ fn is_not_number() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_stdio() {
|
fn is_stdio() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -161,7 +161,7 @@ fn is_stdio() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_not_stdio() {
|
fn is_not_stdio() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "--"]);
|
let raw = clap_lex::RawArgs::new(["bin", "--"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -171,7 +171,7 @@ fn is_not_stdio() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_escape() {
|
fn is_escape() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "--"]);
|
let raw = clap_lex::RawArgs::new(["bin", "--"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -181,7 +181,7 @@ fn is_escape() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_not_escape() {
|
fn is_not_escape() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#[test]
|
#[test]
|
||||||
fn iter() {
|
fn iter() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-short"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-short"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -12,7 +12,7 @@ fn iter() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn next_flag() {
|
fn next_flag() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-short"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-short"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -31,7 +31,7 @@ fn next_flag() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn next_value_os() {
|
fn next_value_os() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-short"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-short"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -44,7 +44,7 @@ fn next_value_os() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn next_flag_with_value() {
|
fn next_flag_with_value() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-short"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-short"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -58,7 +58,7 @@ fn next_flag_with_value() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn next_flag_with_no_value() {
|
fn next_flag_with_no_value() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-short"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-short"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -75,7 +75,7 @@ fn next_flag_with_no_value() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn advance_by_nothing() {
|
fn advance_by_nothing() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-short"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-short"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -89,7 +89,7 @@ fn advance_by_nothing() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn advance_by_nothing_with_nothing() {
|
fn advance_by_nothing_with_nothing() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -103,7 +103,7 @@ fn advance_by_nothing_with_nothing() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn advance_by_something() {
|
fn advance_by_something() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-short"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-short"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -117,7 +117,7 @@ fn advance_by_something() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn advance_by_out_of_bounds() {
|
fn advance_by_out_of_bounds() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-short"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-short"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -131,7 +131,7 @@ fn advance_by_out_of_bounds() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_empty() {
|
fn is_empty() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -142,7 +142,7 @@ fn is_empty() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_not_empty() {
|
fn is_not_empty() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-hello"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-hello"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -153,7 +153,7 @@ fn is_not_empty() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_partial_not_empty() {
|
fn is_partial_not_empty() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-hello"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-hello"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -165,7 +165,7 @@ fn is_partial_not_empty() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_exhausted_empty() {
|
fn is_exhausted_empty() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -177,7 +177,7 @@ fn is_exhausted_empty() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_number() {
|
fn is_number() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-1.0"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-1.0"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
@ -188,7 +188,7 @@ fn is_number() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_not_number() {
|
fn is_not_number() {
|
||||||
let raw = clap_lex::RawArgs::from_iter(["bin", "-hello"]);
|
let raw = clap_lex::RawArgs::new(["bin", "-hello"]);
|
||||||
let mut cursor = raw.cursor();
|
let mut cursor = raw.cursor();
|
||||||
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
assert_eq!(raw.next_os(&mut cursor), Some(std::ffi::OsStr::new("bin")));
|
||||||
let next = raw.next(&mut cursor).unwrap();
|
let next = raw.next(&mut cursor).unwrap();
|
||||||
|
|
|
@ -631,7 +631,7 @@ impl<'help> App<'help> {
|
||||||
I: IntoIterator<Item = T>,
|
I: IntoIterator<Item = T>,
|
||||||
T: Into<OsString> + Clone,
|
T: Into<OsString> + Clone,
|
||||||
{
|
{
|
||||||
let mut raw_args = clap_lex::RawArgs::from(itr.into_iter());
|
let mut raw_args = clap_lex::RawArgs::new(itr.into_iter());
|
||||||
let mut cursor = raw_args.cursor();
|
let mut cursor = raw_args.cursor();
|
||||||
|
|
||||||
#[cfg(feature = "unstable-multicall")]
|
#[cfg(feature = "unstable-multicall")]
|
||||||
|
|
|
@ -651,6 +651,8 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_new_arg(&self, next: &clap_lex::ParsedArg<'_>, current_positional: &Arg) -> bool {
|
fn is_new_arg(&self, next: &clap_lex::ParsedArg<'_>, current_positional: &Arg) -> bool {
|
||||||
|
#![allow(clippy::needless_bool)] // Prefer consistent if/else-if ladder
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Parser::is_new_arg: {:?}:{:?}",
|
"Parser::is_new_arg: {:?}:{:?}",
|
||||||
next.to_value_os(),
|
next.to_value_os(),
|
||||||
|
|
Loading…
Reference in a new issue