diff options
Diffstat (limited to 'crates/shirabe/src/util/hg.rs')
| -rw-r--r-- | crates/shirabe/src/util/hg.rs | 72 |
1 files changed, 44 insertions, 28 deletions
diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs index d5e867c..c3f4b6e 100644 --- a/crates/shirabe/src/util/hg.rs +++ b/crates/shirabe/src/util/hg.rs @@ -1,13 +1,13 @@ //! ref: composer/src/Composer/Util/Hg.php -use std::sync::OnceLock; -use anyhow::Result; -use shirabe_php_shim::rawurlencode; -use shirabe_external_packages::composer::pcre::preg::Preg; use crate::config::Config; use crate::io::io_interface::IOInterface; use crate::util::process_executor::ProcessExecutor; use crate::util::url::Url; +use anyhow::Result; +use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_php_shim::rawurlencode; +use std::sync::OnceLock; static VERSION: OnceLock<Option<String>> = OnceLock::new(); @@ -34,7 +34,11 @@ impl Hg { // Try as is let command = command_callable(url.clone()); let mut ignored_output = String::new(); - if self.process.execute(&command, &mut ignored_output, cwd.clone()) == 0 { + if self + .process + .execute(&command, &mut ignored_output, cwd.clone()) + == 0 + { return Ok(()); } @@ -45,7 +49,10 @@ impl Hg { )?; if let Some(matches) = matches { - if self.io.has_authentication(matches.get("host").map(|s| s.as_str()).unwrap_or("")) { + if self + .io + .has_authentication(matches.get("host").map(|s| s.as_str()).unwrap_or("")) + { let authenticated_url = if matches.get("proto").map(|s| s.as_str()) == Some("ssh") { let user = if let Some(u) = matches.get("user") { format!("{}@", rawurlencode(u)) @@ -60,7 +67,9 @@ impl Hg { matches.get("path").unwrap_or(&String::new()), ) } else { - let auth = self.io.get_authentication(matches.get("host").map(|s| s.as_str()).unwrap_or("")); + let auth = self + .io + .get_authentication(matches.get("host").map(|s| s.as_str()).unwrap_or("")); format!( "{}://{}:{}@{}{}", matches.get("proto").unwrap_or(&String::new()), @@ -78,7 +87,8 @@ impl Hg { } let error = self.process.get_error_output(); - return self.throw_exception(&format!("Failed to clone {}, \n\n{}", url, error), &url); + return self + .throw_exception(&format!("Failed to clone {}, \n\n{}", url, error), &url); } } @@ -91,32 +101,38 @@ impl Hg { fn throw_exception(&self, message: &str, url: &str) -> Result<()> { if Self::get_version(&self.process).is_none() { - anyhow::bail!("{}", Url::sanitize(&format!( - "Failed to clone {}, hg was not found, check that it is installed and in your PATH env.\n\n{}", - url, - self.process.get_error_output() - ))); + anyhow::bail!( + "{}", + Url::sanitize(&format!( + "Failed to clone {}, hg was not found, check that it is installed and in your PATH env.\n\n{}", + url, + self.process.get_error_output() + )) + ); } anyhow::bail!("{}", Url::sanitize(message)); } pub fn get_version(process: &ProcessExecutor) -> Option<&'static str> { - VERSION.get_or_init(|| { - let mut output = String::new(); - if process.execute( - &["hg".to_string(), "--version".to_string()], - &mut output, - None, - ) == 0 { - if let Ok(Some(matches)) = Preg::is_match_with_indexed_captures( - r"/^.+? (\d+(?:\.\d+)+)(?:\+.*?)?\)?\r?\n/", - &output, - ) { - return matches.into_iter().nth(1); + VERSION + .get_or_init(|| { + let mut output = String::new(); + if process.execute( + &["hg".to_string(), "--version".to_string()], + &mut output, + None, + ) == 0 + { + if let Ok(Some(matches)) = Preg::is_match_with_indexed_captures( + r"/^.+? (\d+(?:\.\d+)+)(?:\+.*?)?\)?\r?\n/", + &output, + ) { + return matches.into_iter().nth(1); + } } - } - None - }).as_deref() + None + }) + .as_deref() } } |
