diff options
author | Henrique Alves <henriquelalves@gmail.com> | 2022-07-06 02:13:29 -0300 |
---|---|---|
committer | Henrique Alves <henriquelalves@gmail.com> | 2022-07-25 12:04:15 -0300 |
commit | b48e67262eb517f64cc67aedeafbe74f9fbbe690 (patch) | |
tree | 0811e25e52375a3926db703de9e92f7699d8c86b /src/utils.rs | |
download | glam-b48e67262eb517f64cc67aedeafbe74f9fbbe690.tar.gz glam-b48e67262eb517f64cc67aedeafbe74f9fbbe690.tar.bz2 glam-b48e67262eb517f64cc67aedeafbe74f9fbbe690.zip |
first commit
Diffstat (limited to 'src/utils.rs')
-rw-r--r-- | src/utils.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..271cf6d --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,44 @@ +pub fn get_repo_name(repo: &str) -> String { + let mut chars = repo.chars().rev(); + let length = repo.chars().count(); + let mut last_i = 0; + let mut first_i = 0; + + let mut i = length; + println!("{}", i); + + while i > 0 { + match chars.next() { + Some('.') => { + last_i = i-1; + } + Some('/') => { + first_i = i; + break; + } + _ => {} + } + i -= 1; + } + + if last_i == 0 { + 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:: + new("sh") + .current_dir(folder.unwrap_or("./")) + .arg("-c") + .arg(command) + .status() + .expect("Error running command."); + return status.success(); +} |