summaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorHenrique Alves <henriquelalves@gmail.com>2022-07-25 15:44:54 -0300
committerHenrique Alves <henriquelalves@gmail.com>2022-07-25 15:44:54 -0300
commit8de695eb3cd8a1ed6eb78550b18914856e15f775 (patch)
tree2b417be004a5a1ddaa9f3cfbe47706bc400bdd21 /src/utils.rs
parent3fcc92735d8ed5ee3aae8017cc9f1f31b96089ae (diff)
downloadglam-8de695eb3cd8a1ed6eb78550b18914856e15f775.tar.gz
glam-8de695eb3cd8a1ed6eb78550b18914856e15f775.tar.bz2
glam-8de695eb3cd8a1ed6eb78550b18914856e15f775.zip
Update package commit
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs53
1 files changed, 45 insertions, 8 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 271cf6d..e925f9d 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,3 +1,26 @@
+use colored::Colorize;
+use std::io::Write;
+
+pub fn log_warning(msg: &str) {
+ let msg = format!("⚠️ {}", msg).yellow();
+ println!("{}", msg);
+}
+
+pub fn log_error(msg: &str) {
+ let msg = format!("❌ {}", msg).red();
+ println!("{}", msg);
+}
+
+pub fn log_info(msg: &str) {
+ let msg = format!("ℹ️ {}", msg).blue();
+ println!("{}", msg);
+}
+
+pub fn log_check(msg: &str) {
+ let msg = format!("✅ {}", msg).green();
+ println!("{}", msg);
+}
+
pub fn get_repo_name(repo: &str) -> String {
let mut chars = repo.chars().rev();
let length = repo.chars().count();
@@ -5,7 +28,6 @@ pub fn get_repo_name(repo: &str) -> String {
let mut first_i = 0;
let mut i = length;
- println!("{}", i);
while i > 0 {
match chars.next() {
@@ -25,20 +47,35 @@ pub fn get_repo_name(repo: &str) -> String {
last_i = length;
}
- println!("{} {}", first_i, last_i);
let name = &repo[first_i..last_i];
- println!("{}", name);
// TODO: Return a Result (may be error)
return name.to_string();
}
-pub fn run_shell_command(command : &str, folder : Option<&str>) -> bool {
- let status = std::process::Command::
+pub fn run_shell_command(command : &str, folder : &str, verbose : bool) -> Result<String, String> {
+ let output = std::process::Command::
new("sh")
- .current_dir(folder.unwrap_or("./"))
+ .current_dir(folder)
+ .stdin(std::process::Stdio::inherit())
.arg("-c")
.arg(command)
- .status()
+ .output()
.expect("Error running command.");
- return status.success();
+
+ if verbose {
+ std::io::stdout().write_all(&output.stdout).unwrap();
+ std::io::stderr().write_all(&output.stderr).unwrap();
+ }
+
+ match output.status.success() {
+ true => {
+ let stdout_str = String::from_utf8(output.stdout).unwrap();
+ return Ok(stdout_str);
+ }
+
+ false => {
+ let stderr_str = String::from_utf8(output.stderr).unwrap();
+ return Err(stderr_str);
+ }
+ }
}