Run rustfmt

This commit is contained in:
Elara 2021-06-04 08:59:37 -07:00
parent d528dedee9
commit e843ea02e4
1 changed files with 34 additions and 17 deletions

View File

@ -15,9 +15,13 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{collections::HashMap, env, process::{Command, Child, exit}};
use serde_derive::Deserialize;
use std::fs;
use std::{
collections::HashMap,
env,
process::{exit, Child, Command},
};
use toml;
#[macro_use]
@ -55,7 +59,7 @@ fn main() {
// If no repos provided, error and exit
if config.repos.len() < 1 {
error!("Please add repos to the {} file", CFG_NAME);
exit(1)
exit(1);
}
// If origin repo is not defined, error and exit
@ -70,7 +74,9 @@ fn main() {
// If no arguments provided
if args.len() < 2 {
// Run git --help
let mut proc = Command::new("git").arg("--help").spawn()
let mut proc = Command::new("git")
.arg("--help")
.spawn()
.log_err("Error running git command");
exit_if_code_nonzero(&mut proc);
}
@ -92,11 +98,14 @@ fn main() {
.log_err("Error running git command");
exit_if_code_nonzero(&mut proc);
}
},
}
"init" => {
info!("Intercepted init command");
// Run git init with any preceding arguments
let mut proc = Command::new("git").arg("init").args(&args[2..]).spawn()
let mut proc = Command::new("git")
.arg("init")
.args(&args[2..])
.spawn()
.log_err("Error running git command");
exit_if_code_nonzero(&mut proc);
// For every repo in config
@ -109,18 +118,24 @@ fn main() {
exit_if_code_nonzero(&mut proc);
}
// Run git fetch origin
proc = Command::new("git").args(&["fetch", "origin"]).spawn()
proc = Command::new("git")
.args(&["fetch", "origin"])
.spawn()
.log_err("Error running git command");
exit_if_code_nonzero(&mut proc);
// Run git checkout master
proc = Command::new("git").args(&["checkout", "master"]).spawn()
proc = Command::new("git")
.args(&["checkout", "master"])
.spawn()
.log_err("Error running git command");
exit_if_code_nonzero(&mut proc);
},
}
// Default
_ => {
// Run git, passing through all arguments provided
let mut proc = Command::new("git").args(&args[1..]).spawn()
let mut proc = Command::new("git")
.args(&args[1..])
.spawn()
.log_err("Error running git command");
exit_if_code_nonzero(&mut proc);
}
@ -145,22 +160,24 @@ trait LogErr<T> {
}
// Implement LogErr on Result of any type where E implements Debug
impl<T, E> LogErr<T> for Result<T, E> where E: ::std::fmt::Debug {
impl<T, E> LogErr<T> for Result<T, E>
where
E: ::std::fmt::Debug,
{
// log_err unwraps Result, logging error and exiting if needed
fn log_err(self, msg: &str) -> T {
match self {
// If no error
Ok(res) => {
// Return value within Result
return res
return res;
}
// If error
Err(err) => {
// Log error in format "message: error" and exit
error!("{}: {:?}", msg, err);
exit(1)
},
}
}
}
}