[No-auto] bin/core/imag: Fix Clippy warnings

Signed-off-by: flip1995 <hello@philkrones.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
flip1995 2019-08-27 10:30:44 +02:00 committed by Matthias Beyer
parent 670a0ff6d7
commit 3a1f0dde9d

View file

@ -102,8 +102,7 @@ fn help_text(cmds: Vec<String>) -> String {
.into_iter() .into_iter()
.map(|cmd| format!("\t{}\n", cmd)) .map(|cmd| format!("\t{}\n", cmd))
.fold(String::new(), |s, c| { .fold(String::new(), |s, c| {
let s = s + c.as_str(); s + c.as_str()
s
})) }))
} }
@ -270,74 +269,70 @@ fn main() {
} }
}; };
// Matches any subcommand given // Matches any subcommand given, except calling for example 'imag --versions', as this option
match matches.subcommand() { // does not exit. There's nothing to do in such a case
(subcommand, Some(scmd)) => { if let (subcommand, Some(scmd)) = matches.subcommand() {
// Get all given arguments and further subcommands to pass to // Get all given arguments and further subcommands to pass to
// the imag-<> binary // the imag-<> binary
// Providing no arguments is OK, and is therefore ignored here // Providing no arguments is OK, and is therefore ignored here
let mut subcommand_args : Vec<String> = match scmd.values_of("") { let mut subcommand_args : Vec<String> = match scmd.values_of("") {
Some(values) => values.map(String::from).collect(), Some(values) => values.map(String::from).collect(),
None => Vec::new() None => Vec::new()
}; };
debug!("Processing forwarding of commandline arguments"); debug!("Processing forwarding of commandline arguments");
forward_commandline_arguments(&matches, &mut subcommand_args); forward_commandline_arguments(&matches, &mut subcommand_args);
let subcommand = String::from(subcommand); let subcommand = String::from(subcommand);
let subcommand = aliases.get(&subcommand).cloned().unwrap_or(subcommand); let subcommand = aliases.get(&subcommand).cloned().unwrap_or(subcommand);
debug!("Calling 'imag-{}' with args: {:?}", subcommand, subcommand_args); debug!("Calling 'imag-{}' with args: {:?}", subcommand, subcommand_args);
// Create a Command, and pass it the gathered arguments // Create a Command, and pass it the gathered arguments
match Command::new(format!("imag-{}", subcommand)) match Command::new(format!("imag-{}", subcommand))
.stdin(Stdio::inherit()) .stdin(Stdio::inherit())
.stdout(Stdio::inherit()) .stdout(Stdio::inherit())
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.args(&subcommand_args[..]) .args(&subcommand_args[..])
.spawn() .spawn()
.and_then(|mut c| c.wait()) .and_then(|mut c| c.wait())
{ {
Ok(exit_status) => { Ok(exit_status) => {
if !exit_status.success() { if !exit_status.success() {
debug!("imag-{} exited with non-zero exit code: {:?}", subcommand, exit_status); debug!("imag-{} exited with non-zero exit code: {:?}", subcommand, exit_status);
eprintln!("imag-{} exited with non-zero exit code", subcommand); eprintln!("imag-{} exited with non-zero exit code", subcommand);
exit(exit_status.code().unwrap_or(1)); exit(exit_status.code().unwrap_or(1));
} }
debug!("Successful exit!"); debug!("Successful exit!");
}, },
Err(e) => { Err(e) => {
debug!("Error calling the subcommand"); debug!("Error calling the subcommand");
match e.kind() { match e.kind() {
ErrorKind::NotFound => { ErrorKind::NotFound => {
writeln!(out, "No such command: 'imag-{}'", subcommand) writeln!(out, "No such command: 'imag-{}'", subcommand)
.to_exit_code() .to_exit_code()
.unwrap_or_exit(); .unwrap_or_exit();
writeln!(out, "See 'imag --help' for available subcommands") writeln!(out, "See 'imag --help' for available subcommands")
.to_exit_code() .to_exit_code()
.unwrap_or_exit(); .unwrap_or_exit();
exit(1); exit(1);
}, },
ErrorKind::PermissionDenied => { ErrorKind::PermissionDenied => {
writeln!(out, "No permission to execute: 'imag-{}'", subcommand) writeln!(out, "No permission to execute: 'imag-{}'", subcommand)
.to_exit_code() .to_exit_code()
.unwrap_or_exit(); .unwrap_or_exit();
exit(1); exit(1);
}, },
_ => { _ => {
writeln!(out, "Error spawning: {:?}", e) writeln!(out, "Error spawning: {:?}", e)
.to_exit_code() .to_exit_code()
.unwrap_or_exit(); .unwrap_or_exit();
exit(1); exit(1);
}
} }
} }
} }
}, }
// Calling for example 'imag --versions' will lead here, as this option does not exit.
// There's nothing to do in such a case
_ => {},
} }
} }
@ -353,14 +348,14 @@ fn fetch_aliases(config: Option<&Value>) -> Result<BTreeMap<String, String>, Str
let mut alias_mappings = BTreeMap::new(); let mut alias_mappings = BTreeMap::new();
for (k, v) in tbl { for (k, v) in tbl {
match v { match *v {
&Value::String(ref alias) => { Value::String(ref alias) => {
alias_mappings.insert(alias.clone(), k.clone()); alias_mappings.insert(alias.clone(), k.clone());
}, },
&Value::Array(ref aliases) => { Value::Array(ref aliases) => {
for alias in aliases { for alias in aliases {
match alias { match *alias {
&Value::String(ref s) => { Value::String(ref s) => {
alias_mappings.insert(s.clone(), k.clone()); alias_mappings.insert(s.clone(), k.clone());
}, },
_ => { _ => {