Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
pacak committed Oct 5, 2022
1 parent 9c251f2 commit bb96149
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
10 changes: 6 additions & 4 deletions src/from_os_str.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::{ffi::OsString, path::PathBuf, str::FromStr};
use std::{
any::{Any, TypeId},
ffi::OsString,
path::PathBuf,
str::FromStr,
};

pub(crate) fn parse_os_str<T>(os: OsString) -> Result<T, String>
where
T: FromStr + 'static,
<T as std::str::FromStr>::Err: std::fmt::Display,
{
use std::any::Any;
use std::any::*;

if TypeId::of::<T>() == TypeId::of::<OsString>() {
let anybox: Box<dyn Any> = Box::new(os);
Ok(*(anybox.downcast::<T>().unwrap()))
Expand Down
53 changes: 25 additions & 28 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,38 +866,35 @@ fn parse_word(
metavar: &'static str,
help: &Option<String>,
) -> Result<OsString, Error> {
match args.take_positional_word()? {
Some((is_strict, word)) => {
if strict && !is_strict {
#[cfg(feature = "autocomplete")]
args.push_value("--", &Some("-- Positional only items".to_owned()), false);

return Err(Error::Stderr(format!(
"Expected <{}> to be on the right side of --",
metavar,
)));
}
#[cfg(feature = "autocomplete")]
if args.touching_last_remove() && !args.no_pos_ahead {
args.push_metadata(metavar, help, false);
args.no_pos_ahead = true;
}
Ok(word)
}
None => {
if let Some((is_strict, word)) = args.take_positional_word()? {
if strict && !is_strict {
#[cfg(feature = "autocomplete")]
if !args.no_pos_ahead {
args.push_metadata(metavar, help, false);
args.no_pos_ahead = true;
}
args.push_value("--", &Some("-- Positional only items".to_owned()), false);

let item = Item::Positional {
return Err(Error::Stderr(format!(
"Expected <{}> to be on the right side of --",
metavar,
help: help.clone(),
strict,
};
Err(Error::Missing(vec![item]))
)));
}
#[cfg(feature = "autocomplete")]
if args.touching_last_remove() && !args.no_pos_ahead {
args.push_metadata(metavar, help, false);
args.no_pos_ahead = true;
}
Ok(word)
} else {
#[cfg(feature = "autocomplete")]
if !args.no_pos_ahead {
args.push_metadata(metavar, help, false);
args.no_pos_ahead = true;
}

let item = Item::Positional {
metavar,
help: help.clone(),
strict,
};
Err(Error::Missing(vec![item]))
}
}

Expand Down

0 comments on commit bb96149

Please sign in to comment.