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