From ef6a0bc483b00af5eee65c331ad273be7ccfbbca Mon Sep 17 00:00:00 2001 From: jan Michal Date: Sat, 5 Feb 2022 15:17:32 +0000 Subject: [PATCH] now lets you pull specific packages & added reinit --- Cargo.toml | 2 +- PKGBUILD | 4 +- src/main.rs | 103 +++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 88 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eb3dade..7ee1b96 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Malachite" -version = "0.1.0" +version = "1.1.0" authors = [ "michal " ] edition = "2021" description = "Packaging tool for pacman repositories" diff --git a/PKGBUILD b/PKGBUILD index e16c72d..8f6051b 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Matt C pkgname=malachite -pkgver=1.0.0 +pkgver=1.1.0 pkgrel=1 pkgdesc="Tool for packaging and maintaining pacman repositories" arch=('any') @@ -21,4 +21,4 @@ package() { mkdir -p $pkgdir/usr/bin chmod +x ${srcdir}/malachite/target/release/mlc cp ${srcdir}/malachite/target/release/mlc $pkgdir/usr/bin/. -} +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 1292a13..6c23393 100755 --- a/src/main.rs +++ b/src/main.rs @@ -76,10 +76,20 @@ fn main() { .subcommand(SubCommand::with_name("init").about( "Clones all git repositories from mlc.toml branching from current directory", )) + .subcommand(SubCommand::with_name("reinit")) + .about("Removes all subdirectories and reinitialises") .subcommand( - SubCommand::with_name("pull").alias("update").about( - "Pulls all git repositories from mlc.toml branching from current directory", - ), + SubCommand::with_name("pull") + .alias("update") + .about( + "Pulls all git repositories from mlc.toml branching from current directory", + ) + .arg( + Arg::with_name("package(s)") + .help("The packages to operate on") + .multiple(true) + .index(1), + ), ) .subcommand( SubCommand::with_name("config").about("Create and/or open local config file"), @@ -148,6 +158,39 @@ fn main() { } } + if let true = matches.is_present("reinit") { + let config = workspace::read_cfg(); + Command::new("bash") + .args(&["-c", "rm -rf */"]) + .spawn() + .unwrap() + .wait() + .unwrap(); + if config.mode == "workspace" { + for r in config.repo { + info(format!("Cloning (workspace mode): {}", r)); + Command::new("git") + .args(&["clone", &r]) + .spawn() + .unwrap() + .wait() + .unwrap(); + } + } else if config.mode == "repository" { + for r in config.repo { + info(format!("Cloning (repository mode): {}", r)); + Command::new("git") + .args(&["clone", &r]) + .spawn() + .unwrap() + .wait() + .unwrap(); + } + } else { + crash("Invalid mode in mlc.toml".to_string(), 1); + } + } + if let true = matches.is_present("build") { let config = workspace::read_cfg(); let mut packages: Vec = matches @@ -215,23 +258,47 @@ fn main() { } if let true = matches.is_present("pull") { + let packages: Vec = matches + .subcommand_matches("pull") + .unwrap() + .values_of_lossy("package(s)") + .unwrap_or_default(); let config = workspace::read_cfg(); let cdir = env::current_dir().unwrap(); - for r in config.repo { - info(format!("Entering working directory: {}", r)); - let dir = format!( - "{}/{}", - env::current_dir().unwrap().display(), - r.split('/').collect::>().last().unwrap() - ); - env::set_current_dir(dir).unwrap(); - Command::new("git") - .args(&["pull", &r]) - .spawn() - .unwrap() - .wait() - .unwrap(); - env::set_current_dir(&cdir).unwrap(); + if packages.is_empty() { + for r in config.repo { + info(format!("Entering working directory: {}", r)); + let dir = format!( + "{}/{}", + env::current_dir().unwrap().display(), + r.split('/').collect::>().last().unwrap() + ); + env::set_current_dir(dir).unwrap(); + Command::new("git") + .args(&["pull", &r]) + .spawn() + .unwrap() + .wait() + .unwrap(); + env::set_current_dir(&cdir).unwrap(); + } + } else { + for r in packages { + info(format!("Entering working directory: {}", r)); + let dir = format!( + "{}/{}", + env::current_dir().unwrap().display(), + r.split('/').collect::>().last().unwrap() + ); + env::set_current_dir(dir).unwrap(); + Command::new("git") + .args(&["pull", &r]) + .spawn() + .unwrap() + .wait() + .unwrap(); + env::set_current_dir(&cdir).unwrap(); + } } }