initial commit for clapv3
parent
1910fc8fdd
commit
1e12021241
@ -0,0 +1,67 @@
|
|||||||
|
use clap::{ArgAction, Parser, Subcommand};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Parser)]
|
||||||
|
#[clap(name="Malachite", version=env!("CARGO_PKG_VERSION"), about=env!("CARGO_PKG_DESCRIPTION"))]
|
||||||
|
pub struct Args {
|
||||||
|
#[clap(subcommand)]
|
||||||
|
pub subcommand: Option<Operation>,
|
||||||
|
|
||||||
|
/// Sets the level of verbosity
|
||||||
|
#[clap(long, short, global(true), action=ArgAction::Count)]
|
||||||
|
pub verbose: u8,
|
||||||
|
|
||||||
|
/// Complete operations without prompting user
|
||||||
|
#[clap(long="noconfirm", global(true), action=ArgAction::SetTrue)]
|
||||||
|
pub no_confirm: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Subcommand)]
|
||||||
|
pub enum Operation {
|
||||||
|
/// Builds the given packages
|
||||||
|
#[clap(name="build", aliases=&["b"])]
|
||||||
|
Build {
|
||||||
|
/// The packages to operate on
|
||||||
|
#[clap(name="package(s)", action=ArgAction::Append, index=1)]
|
||||||
|
packages: Vec<String>,
|
||||||
|
|
||||||
|
/// Builds all packages in mlc.toml (except if -x is specified)
|
||||||
|
#[clap(long="all", action=ArgAction::Append, takes_value=true, conflicts_with="package(s)")]
|
||||||
|
all: bool,
|
||||||
|
|
||||||
|
/// Excludes packages from given operation
|
||||||
|
#[clap(short='x', long="exclude", action=ArgAction::Append, takes_value=true)]
|
||||||
|
exclude: Vec<String>,
|
||||||
|
|
||||||
|
/// Does not regenerate repository after building given package(s)
|
||||||
|
#[clap(short='n', long="no-regen", action=ArgAction::SetTrue)]
|
||||||
|
no_regen: bool,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Generates repository from built packages
|
||||||
|
#[clap(name="repo-gen", aliases=&["r"])]
|
||||||
|
RepoGen,
|
||||||
|
|
||||||
|
/// Prunes duplicate packages from the repository
|
||||||
|
#[clap(name="prune", aliases=&["p"])]
|
||||||
|
Prune,
|
||||||
|
|
||||||
|
/// Clones all git repositories from mlc.toml branching from current directory
|
||||||
|
#[clap(name="init", aliases=&["i"])]
|
||||||
|
Init,
|
||||||
|
|
||||||
|
/// Pulls in git repositories from mlc.toml branching from current directory
|
||||||
|
#[clap(name="pull", aliases=&["u"])]
|
||||||
|
Pull {
|
||||||
|
/// The packages to operate on
|
||||||
|
#[clap(name="package(s)", help="The packages to operate on", action=ArgAction::Append, index=1)]
|
||||||
|
packages: Vec<String>,
|
||||||
|
|
||||||
|
/// Pulls from all git repositories from mlc.toml branching from current directory
|
||||||
|
#[clap(long="all", action=ArgAction::SetTrue)]
|
||||||
|
all: bool,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Create and/or open local config file
|
||||||
|
#[clap(name="config", aliases=&["c"])]
|
||||||
|
Config,
|
||||||
|
}
|
@ -1,27 +1,11 @@
|
|||||||
use clap::ArgMatches;
|
|
||||||
|
|
||||||
mod build;
|
mod build;
|
||||||
mod config;
|
mod config;
|
||||||
mod init;
|
mod init;
|
||||||
mod prune;
|
mod prune;
|
||||||
mod pull;
|
mod pull;
|
||||||
|
|
||||||
pub fn init() {
|
pub use build::*;
|
||||||
init::init();
|
pub use config::*;
|
||||||
}
|
pub use init::*;
|
||||||
|
pub use prune::*;
|
||||||
pub fn build(matches: &ArgMatches) {
|
pub use pull::*;
|
||||||
build::build(matches);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pull(matches: &ArgMatches) {
|
|
||||||
pull::pull(matches);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn config() {
|
|
||||||
config::config();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prune() {
|
|
||||||
prune::prune();
|
|
||||||
}
|
|
||||||
|
@ -1,47 +1,34 @@
|
|||||||
use crate::info;
|
use crate::info;
|
||||||
use clap::ArgMatches;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub fn pull(matches: &ArgMatches) {
|
fn do_the_pulling(packages: Vec<String>) {
|
||||||
let packages: Vec<String> = matches
|
for dir in packages {
|
||||||
.subcommand_matches("pull")
|
let current_dir = env::current_dir().unwrap();
|
||||||
.unwrap()
|
info(format!("Entering working directory: {}", dir));
|
||||||
.values_of_lossy("package(s)")
|
env::set_current_dir(dir).unwrap();
|
||||||
.unwrap_or_default();
|
Command::new("git")
|
||||||
|
.arg("pull")
|
||||||
|
.spawn()
|
||||||
|
.unwrap()
|
||||||
|
.wait()
|
||||||
|
.unwrap();
|
||||||
|
env::set_current_dir(current_dir).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if packages.is_empty() {
|
pub fn pull(packages: Vec<String>, all: bool) {
|
||||||
|
if all {
|
||||||
let stdout = Command::new("ls").arg("-1").output().unwrap().stdout;
|
let stdout = Command::new("ls").arg("-1").output().unwrap().stdout;
|
||||||
let dirs_string = String::from_utf8_lossy(&stdout);
|
let dirs_string = String::from_utf8_lossy(&stdout);
|
||||||
|
|
||||||
let mut dirs = dirs_string.lines().collect::<Vec<&str>>();
|
let mut dirs = dirs_string.lines().collect::<Vec<&str>>();
|
||||||
|
|
||||||
dirs.retain(|x| *x != "mlc.toml");
|
dirs.retain(|x| *x != "mlc.toml");
|
||||||
|
let dirs_mapped = dirs.iter().map(|x| x.to_string()).collect();
|
||||||
|
|
||||||
for dir in dirs {
|
do_the_pulling(dirs_mapped);
|
||||||
let cdir = env::current_dir().unwrap();
|
|
||||||
info(format!("Entering working directory: {}", dir));
|
|
||||||
env::set_current_dir(dir).unwrap();
|
|
||||||
Command::new("git")
|
|
||||||
.arg("pull")
|
|
||||||
.spawn()
|
|
||||||
.unwrap()
|
|
||||||
.wait()
|
|
||||||
.unwrap();
|
|
||||||
env::set_current_dir(cdir).unwrap();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for dir in packages {
|
do_the_pulling(packages);
|
||||||
let cdir = env::current_dir().unwrap();
|
|
||||||
info(format!("Entering working directory: {}", dir));
|
|
||||||
env::set_current_dir(dir).unwrap();
|
|
||||||
Command::new("git")
|
|
||||||
.arg("pull")
|
|
||||||
.spawn()
|
|
||||||
.unwrap()
|
|
||||||
.wait()
|
|
||||||
.unwrap();
|
|
||||||
env::set_current_dir(cdir).unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
use crate::internal::structs::Config;
|
|
||||||
|
|
||||||
mod read;
|
mod read;
|
||||||
|
|
||||||
pub fn read_cfg() -> Config {
|
pub use read::*;
|
||||||
read::read_cfg()
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue