Prompt for package building + fixed spinner

main
Michal 2 years ago committed by GitHub
parent 4586266b7b
commit 91a2adc1f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

16
Cargo.lock generated

@ -137,9 +137,9 @@ dependencies = [
[[package]]
name = "crossterm"
version = "0.24.0"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab9f7409c70a38a56216480fba371ee460207dd8926ccf5b4160591759559170"
checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67"
dependencies = [
"bitflags",
"crossterm_winapi",
@ -485,14 +485,14 @@ checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1"
[[package]]
name = "spinoff"
version = "0.5.2"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d3f754b5a185a81fa60acbd32f095411e276743d27307a531d34eae5d49c991"
checksum = "3c139aa6a2b4ed01ef761dfd593eb5b02218dbf35a3a0f10940b72f5bfe70426"
dependencies = [
"colored",
"maplit",
"once_cell",
"strum",
"yansi",
]
[[package]]
@ -729,9 +729,3 @@ name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]]
name = "yansi"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"

@ -27,9 +27,9 @@ serde_derive = { version = "1.0.139", default-features = false }
libc = { version = "0.2.126", default-features = false }
colored = { version = "2.0.0", default-features = false }
tabled = { version = "0.8.0", default-features = false, features = ["derive", "color"] }
crossterm = { version = "0.24.0", default-features = false }
crossterm = { version = "0.25.0", default-features = false }
regex = { version = "1.6.0", default-features = false, features = ["std"] }
spinoff = { version = "0.5.2", default-features = false }
spinoff = { version = "0.5.3", default-features = false }
rm_rf = { version = "0.6.2", default-features = false }
[target.'cfg(target_os = "linux")'.dependencies]

@ -63,6 +63,10 @@ pub enum Operation {
/// Does not regenerate repository after pulling given package(s). This only applies if build_on_update is set to true in repository config
#[clap(short = 'n', long = "no-regen", action = ArgAction::SetTrue)]
no_regen: bool,
/// Will not prompt for confirmation before rebuilding a package
#[clap(long, action = ArgAction::SetTrue)]
no_confirm: bool,
},
/// Create and/or open local config file

@ -28,6 +28,13 @@ macro_rules! crash {
}
}
#[macro_export]
macro_rules! prompt {
(default $default:expr, $($arg:tt)+) => {
$crate::internal::strings::prompt_fn(&format!($($arg)+), $default)
};
}
pub fn info_fn(msg: &str) {
println!("{} {}", LOGO_SYMBOL.green(), msg.bold());
}
@ -49,3 +56,20 @@ pub fn crash_fn(msg: &str, exit_code: AppExitCode) {
println!("{} {}", ERR_SYMBOL.red(), msg.bold());
exit(exit_code as i32);
}
pub fn prompt_fn(msg: &str, default: bool) -> bool {
let yn = if default { "[Y/n]" } else { "[y/N]" };
print!("{} {} {}", "?".bold().green(), msg.bold(), yn);
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let input = input.trim().to_lowercase();
if input == "y" || input == "yes" {
true
} else if input == "n" || input == "no" {
false
} else {
default
}
}

@ -58,8 +58,11 @@ fn main() {
operations::build(&packages, exclude.clone(), no_regen, verbose);
}
Operation::Pull {
packages, no_regen, ..
} => operations::pull(packages, exclude, verbose, no_regen),
packages,
no_regen,
no_confirm,
..
} => operations::pull(packages, exclude, verbose, no_regen, no_confirm),
Operation::RepoGen => {
if !repository(verbose) {
crash!(

@ -162,7 +162,10 @@ pub fn info(verbose: bool) {
.unwrap();
// Stop the spinner with a success message
sp.success(&"Done!".bold());
let text = format!("{}", "Parsing Git Info... Done".bold());
let symbol = format!("{}", "✔".bold().green());
sp.stop_and_persist(&symbol, &text);
log!(verbose, "Repos: {:?}", repos);
}

@ -2,7 +2,7 @@ use std::env;
use std::process::Command;
use crate::info;
use crate::{crash, internal::AppExitCode, log};
use crate::{crash, internal::AppExitCode, log, prompt};
struct PullParams {
smart_pull: bool,
@ -10,7 +10,7 @@ struct PullParams {
no_regen: bool,
}
fn do_the_pulling(repos: Vec<String>, verbose: bool, params: &PullParams) {
fn do_the_pulling(repos: Vec<String>, verbose: bool, params: &PullParams, no_confirm: bool) {
for repo in repos {
// Set root dir to return after each git pull
let root_dir = env::current_dir().unwrap();
@ -54,9 +54,16 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, params: &PullParams) {
// If build_on_update is set, rebuild package
if params.build_on_update {
info!("Package {} updated, staging for rebuild", &repo);
log!(verbose, "Pushing package {} to be rebuilt", &repo);
packages_to_rebuild.push(repo);
if no_confirm {
packages_to_rebuild.push(repo);
} else {
let cont = prompt!(default true, "Rebuild package {}?", &repo);
if cont {
info!("Package {} updated, staging for rebuild", &repo);
log!(verbose, "Pushing package {} to be rebuilt", &repo);
packages_to_rebuild.push(repo);
}
}
}
} else {
// If there are no changes, alert the user
@ -87,7 +94,7 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, params: &PullParams) {
// Push to build
crate::operations::build(&packages_to_rebuild, vec![], params.no_regen, verbose);
// Ensure you are in root dir
env::set_current_dir(root_dir).unwrap();
log!(
@ -99,7 +106,13 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, params: &PullParams) {
}
}
pub fn pull(packages: Vec<String>, exclude: &[String], verbose: bool, no_regen: bool) {
pub fn pull(
packages: Vec<String>,
exclude: &[String],
verbose: bool,
no_regen: bool,
no_confirm: bool,
) {
// Read config file
let config = crate::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
@ -187,5 +200,6 @@ pub fn pull(packages: Vec<String>, exclude: &[String], verbose: bool, no_regen:
build_on_update,
no_regen,
},
no_confirm,
);
}

Loading…
Cancel
Save