reworked pull code

main
jan Michal 3 years ago
parent 1c30abd43e
commit ccf065f819
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -1,4 +1,4 @@
use crate::{info, workspace}; use crate::info;
use clap::ArgMatches; use clap::ArgMatches;
use std::env; use std::env;
use std::process::Command; use std::process::Command;
@ -9,41 +9,39 @@ pub fn pull(matches: &ArgMatches) {
.unwrap() .unwrap()
.values_of_lossy("package(s)") .values_of_lossy("package(s)")
.unwrap_or_default(); .unwrap_or_default();
let config = workspace::read_cfg();
let cdir = env::current_dir().unwrap();
if packages.is_empty() { if packages.is_empty() {
for r in config.repo { let stdout = Command::new("ls").arg("-1").output().unwrap().stdout;
info(format!("Entering working directory: {}", r)); let dirs_string = String::from_utf8_lossy(&stdout);
let dir = format!(
"{}/{}", let mut dirs = dirs_string.lines().collect::<Vec<&str>>();
env::current_dir().unwrap().display(),
r.split('/').collect::<Vec<&str>>().last().unwrap() dirs.retain(|x| *x != "mlc.toml");
);
for dir in dirs {
let cdir = env::current_dir().unwrap();
info(format!("Entering working directory: {}", dir));
env::set_current_dir(dir).unwrap(); env::set_current_dir(dir).unwrap();
Command::new("git") Command::new("git")
.args(&["pull", &r]) .arg("pull")
.spawn() .spawn()
.unwrap() .unwrap()
.wait() .wait()
.unwrap(); .unwrap();
env::set_current_dir(&cdir).unwrap(); env::set_current_dir(cdir).unwrap();
} }
} else { } else {
for r in packages { for dir in packages {
info(format!("Entering working directory: {}", r)); let cdir = env::current_dir().unwrap();
let dir = format!( info(format!("Entering working directory: {}", dir));
"{}/{}",
env::current_dir().unwrap().display(),
r.split('/').collect::<Vec<&str>>().last().unwrap()
);
env::set_current_dir(dir).unwrap(); env::set_current_dir(dir).unwrap();
Command::new("git") Command::new("git")
.args(&["pull", &r]) .arg("pull")
.spawn() .spawn()
.unwrap() .unwrap()
.wait() .wait()
.unwrap(); .unwrap();
env::set_current_dir(&cdir).unwrap(); env::set_current_dir(cdir).unwrap();
} }
} }
} }

Loading…
Cancel
Save