mirror of
https://github.com/Noratrieb/badargs.git
synced 2026-01-14 19:55:08 +01:00
clippy lints
This commit is contained in:
parent
d70a36858f
commit
3fb8953ff4
2 changed files with 11 additions and 13 deletions
20
src/parse.rs
20
src/parse.rs
|
|
@ -17,9 +17,7 @@ impl CliArgs {
|
||||||
let mut result = Self::default();
|
let mut result = Self::default();
|
||||||
|
|
||||||
while let Some(arg) = args.next() {
|
while let Some(arg) = args.next() {
|
||||||
let arg = arg
|
let arg = arg.into_string().map_err(CallError::InvalidUtf8)?;
|
||||||
.into_string()
|
|
||||||
.map_err(|os_str| CallError::InvalidUtf8(os_str))?;
|
|
||||||
|
|
||||||
if let Some(long) = arg.strip_prefix("--") {
|
if let Some(long) = arg.strip_prefix("--") {
|
||||||
parse_long(schema, &mut result, long, &mut args)?;
|
parse_long(schema, &mut result, long, &mut args)?;
|
||||||
|
|
@ -66,9 +64,9 @@ fn parse_shorts(
|
||||||
if let Some(flag) = first_flag {
|
if let Some(flag) = first_flag {
|
||||||
let command = schema
|
let command = schema
|
||||||
.short(flag)
|
.short(flag)
|
||||||
.ok_or_else(|| CallError::ShortFlagNotFound(flag))?;
|
.ok_or(CallError::ShortFlagNotFound(flag))?;
|
||||||
|
|
||||||
parse_value(command.kind, results, &command.long, args)?;
|
parse_value(command.kind, results, command.long, args)?;
|
||||||
} else {
|
} else {
|
||||||
// '-' is a valid argument, like the `cat -`
|
// '-' is a valid argument, like the `cat -`
|
||||||
results.unnamed.push("-".to_string());
|
results.unnamed.push("-".to_string());
|
||||||
|
|
@ -77,10 +75,10 @@ fn parse_shorts(
|
||||||
for flag in all_shorts {
|
for flag in all_shorts {
|
||||||
let command = schema
|
let command = schema
|
||||||
.short(flag)
|
.short(flag)
|
||||||
.ok_or_else(|| CallError::ShortFlagNotFound(flag))?;
|
.ok_or(CallError::ShortFlagNotFound(flag))?;
|
||||||
|
|
||||||
if let SchemaKind::Bool = command.kind {
|
if let SchemaKind::Bool = command.kind {
|
||||||
results.insert(&command.long, Box::new(true));
|
results.insert(command.long, Box::new(true));
|
||||||
} else {
|
} else {
|
||||||
return Err(CallError::CombinedShortWithValue(command.long.to_string()));
|
return Err(CallError::CombinedShortWithValue(command.long.to_string()));
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +97,7 @@ fn parse_long(
|
||||||
.long(long)
|
.long(long)
|
||||||
.ok_or_else(|| CallError::LongFlagNotFound(long.to_string()))?;
|
.ok_or_else(|| CallError::LongFlagNotFound(long.to_string()))?;
|
||||||
|
|
||||||
parse_value(command.kind, results, &command.long, args)
|
parse_value(command.kind, results, command.long, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_value(
|
fn parse_value(
|
||||||
|
|
@ -114,7 +112,7 @@ fn parse_value(
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| CallError::ExpectedValue(long.to_string(), kind))?
|
.ok_or_else(|| CallError::ExpectedValue(long.to_string(), kind))?
|
||||||
.into_string()
|
.into_string()
|
||||||
.map_err(|os_str| CallError::InvalidUtf8(os_str))?;
|
.map_err(CallError::InvalidUtf8)?;
|
||||||
results.insert(long, Box::new(string));
|
results.insert(long, Box::new(string));
|
||||||
}
|
}
|
||||||
SchemaKind::INum => {
|
SchemaKind::INum => {
|
||||||
|
|
@ -122,7 +120,7 @@ fn parse_value(
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| CallError::ExpectedValue(long.to_string(), kind))?
|
.ok_or_else(|| CallError::ExpectedValue(long.to_string(), kind))?
|
||||||
.into_string()
|
.into_string()
|
||||||
.map_err(|os_str| CallError::InvalidUtf8(os_str))?
|
.map_err(CallError::InvalidUtf8)?
|
||||||
.parse::<isize>()
|
.parse::<isize>()
|
||||||
.map_err(|_| CallError::INan(long.to_string()))?;
|
.map_err(|_| CallError::INan(long.to_string()))?;
|
||||||
results.insert(long, Box::new(integer))
|
results.insert(long, Box::new(integer))
|
||||||
|
|
@ -132,7 +130,7 @@ fn parse_value(
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| CallError::ExpectedValue(long.to_string(), kind))?
|
.ok_or_else(|| CallError::ExpectedValue(long.to_string(), kind))?
|
||||||
.into_string()
|
.into_string()
|
||||||
.map_err(|os_str| CallError::InvalidUtf8(os_str))?
|
.map_err(CallError::InvalidUtf8)?
|
||||||
.parse::<usize>()
|
.parse::<usize>()
|
||||||
.map_err(|_| CallError::UNan(long.to_string()))?;
|
.map_err(|_| CallError::UNan(long.to_string()))?;
|
||||||
results.insert(long, Box::new(integer))
|
results.insert(long, Box::new(integer))
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ impl Schema {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_command(&mut self, long_name: &'static str, command: SchemaCommand) -> Result<()> {
|
fn add_command(&mut self, long_name: &'static str, command: SchemaCommand) -> Result<()> {
|
||||||
if let Some(_) = self.longs.insert(long_name, command) {
|
if self.longs.insert(long_name, command).is_some() {
|
||||||
Err(SchemaError::NameAlreadyExists(long_name.to_string()))
|
Err(SchemaError::NameAlreadyExists(long_name.to_string()))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -64,7 +64,7 @@ impl Schema {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_short_command(&mut self, short_name: char, command: SchemaCommand) -> Result<()> {
|
fn add_short_command(&mut self, short_name: char, command: SchemaCommand) -> Result<()> {
|
||||||
if let Some(_) = self.shorts.insert(short_name, command) {
|
if self.shorts.insert(short_name, command).is_some() {
|
||||||
Err(SchemaError::NameAlreadyExists(short_name.to_string()))
|
Err(SchemaError::NameAlreadyExists(short_name.to_string()))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue