Selective yes (fix #802) (#808)

* Selective yes flag (fix #802)

* Selective yes flag (fix #802)

* selective yes

* MacOS
This commit is contained in:
Roey Darwish Dror
2021-12-06 14:44:20 +02:00
committed by GitHub
parent 4b8cf641a1
commit ab3ff0ecae
11 changed files with 77 additions and 59 deletions

View File

@@ -7,6 +7,7 @@ jobs:
strategy: strategy:
matrix: matrix:
platform: [ubuntu-latest, macos-latest, windows-latest] platform: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2

View File

@@ -393,9 +393,9 @@ pub struct CommandLineArgs {
#[structopt(short = "k", long = "keep")] #[structopt(short = "k", long = "keep")]
keep_at_end: bool, keep_at_end: bool,
/// Say yes to package manager's prompt (experimental) /// Say yes to package manager's prompt
#[structopt(short = "y", long = "yes")] #[structopt(short = "y", long = "yes")]
yes: bool, yes: Option<Vec<Step>>,
/// Don't pull the predefined git repos /// Don't pull the predefined git repos
#[structopt(long = "disable-predefined-git-repos")] #[structopt(long = "disable-predefined-git-repos")]
@@ -585,8 +585,20 @@ impl Config {
/// Whether to say yes to package managers /// Whether to say yes to package managers
#[allow(dead_code)] #[allow(dead_code)]
pub fn yes(&self) -> bool { pub fn yes(&self, step: Step) -> bool {
self.config_file.assume_yes.unwrap_or(self.opt.yes) if let Some(yes) = self.config_file.assume_yes {
return yes;
}
if let Some(yes_list) = &self.opt.yes {
if yes_list.is_empty() {
return true;
}
return yes_list.contains(&step);
}
false
} }
/// Bash-it branch /// Bash-it branch

View File

@@ -1,12 +1,15 @@
use crate::execution_context::ExecutionContext;
use crate::terminal::print_separator;
use crate::utils::{require, require_option, PathExt};
use anyhow::Result;
use directories::BaseDirs;
#[cfg(any(windows, target_os = "macos"))] #[cfg(any(windows, target_os = "macos"))]
use std::env; use std::env;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use anyhow::Result;
use directories::BaseDirs;
use crate::execution_context::ExecutionContext;
use crate::terminal::print_separator;
use crate::utils::{require, require_option, PathExt};
use crate::Step;
const EMACS_UPGRADE: &str = include_str!("emacs.el"); const EMACS_UPGRADE: &str = include_str!("emacs.el");
#[cfg(windows)] #[cfg(windows)]
const DOOM_PATH: &str = "bin/doom.cmd"; const DOOM_PATH: &str = "bin/doom.cmd";
@@ -66,7 +69,7 @@ impl Emacs {
let mut command = ctx.run_type().execute(doom); let mut command = ctx.run_type().execute(doom);
command.args(&["-y", "upgrade"]); command.args(&["-y", "upgrade"]);
if ctx.config().yes() { if ctx.config().yes(Step::Emacs) {
command.arg("--force"); command.arg("--force");
} }

View File

@@ -1,6 +1,6 @@
use crate::config;
use crate::execution_context::ExecutionContext; use crate::execution_context::ExecutionContext;
use crate::utils::which; use crate::utils::which;
use crate::{config, Step};
use anyhow::Result; use anyhow::Result;
use std::env::var_os; use std::env::var_os;
use std::ffi::OsString; use std::ffi::OsString;
@@ -42,7 +42,7 @@ impl ArchPackageManager for YayParu {
.args(ctx.config().yay_arguments().split_whitespace()) .args(ctx.config().yay_arguments().split_whitespace())
.env("PATH", get_execution_path()); .env("PATH", get_execution_path());
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("--noconfirm"); command.arg("--noconfirm");
} }
command.check_run()?; command.check_run()?;
@@ -50,7 +50,7 @@ impl ArchPackageManager for YayParu {
if ctx.config().cleanup() { if ctx.config().cleanup() {
let mut command = ctx.run_type().execute(&self.executable); let mut command = ctx.run_type().execute(&self.executable);
command.arg("--pacman").arg(&self.pacman).arg("-Scc"); command.arg("--pacman").arg(&self.pacman).arg("-Scc");
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("--noconfirm"); command.arg("--noconfirm");
} }
command.check_run()?; command.check_run()?;
@@ -82,7 +82,7 @@ impl ArchPackageManager for Trizen {
.args(ctx.config().trizen_arguments().split_whitespace()) .args(ctx.config().trizen_arguments().split_whitespace())
.env("PATH", get_execution_path()); .env("PATH", get_execution_path());
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("--noconfirm"); command.arg("--noconfirm");
} }
command.check_run()?; command.check_run()?;
@@ -90,7 +90,7 @@ impl ArchPackageManager for Trizen {
if ctx.config().cleanup() { if ctx.config().cleanup() {
let mut command = ctx.run_type().execute(&self.executable); let mut command = ctx.run_type().execute(&self.executable);
command.arg("-Sc"); command.arg("-Sc");
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("--noconfirm"); command.arg("--noconfirm");
} }
command.check_run()?; command.check_run()?;
@@ -120,7 +120,7 @@ impl ArchPackageManager for Pacman {
.arg(&self.executable) .arg(&self.executable)
.arg("-Syu") .arg("-Syu")
.env("PATH", get_execution_path()); .env("PATH", get_execution_path());
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("--noconfirm"); command.arg("--noconfirm");
} }
command.check_run()?; command.check_run()?;
@@ -128,7 +128,7 @@ impl ArchPackageManager for Pacman {
if ctx.config().cleanup() { if ctx.config().cleanup() {
let mut command = ctx.run_type().execute(&self.sudo); let mut command = ctx.run_type().execute(&self.sudo);
command.arg(&self.executable).arg("-Scc"); command.arg(&self.executable).arg("-Scc");
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("--noconfirm"); command.arg("--noconfirm");
} }
command.check_run()?; command.check_run()?;

View File

@@ -4,6 +4,7 @@ use crate::executor::{CommandExt, RunType};
use crate::steps::os::archlinux; use crate::steps::os::archlinux;
use crate::terminal::{print_separator, print_warning}; use crate::terminal::{print_separator, print_warning};
use crate::utils::{require, require_option, which, PathExt}; use crate::utils::{require, require_option, which, PathExt};
use crate::Step;
use anyhow::Result; use anyhow::Result;
use ini::Ini; use ini::Ini;
use log::debug; use log::debug;
@@ -137,7 +138,7 @@ fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> {
if ctx.config().rpm_ostree() { if ctx.config().rpm_ostree() {
let mut command = ctx.run_type().execute(ostree); let mut command = ctx.run_type().execute(ostree);
command.arg("upgrade"); command.arg("upgrade");
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("-y"); command.arg("-y");
} }
@@ -163,7 +164,7 @@ fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> {
command.args(args.split_whitespace()); command.args(args.split_whitespace());
} }
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("-y"); command.arg("-y");
} }
@@ -259,7 +260,7 @@ fn upgrade_debian(ctx: &ExecutionContext) -> Result<()> {
let mut command = ctx.run_type().execute(&sudo); let mut command = ctx.run_type().execute(&sudo);
command.arg(&apt).arg("dist-upgrade"); command.arg(&apt).arg("dist-upgrade");
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("-y"); command.arg("-y");
} }
if let Some(args) = ctx.config().apt_arguments() { if let Some(args) = ctx.config().apt_arguments() {
@@ -272,7 +273,7 @@ fn upgrade_debian(ctx: &ExecutionContext) -> Result<()> {
let mut command = ctx.run_type().execute(&sudo); let mut command = ctx.run_type().execute(&sudo);
command.arg(&apt).arg("autoremove"); command.arg(&apt).arg("autoremove");
if ctx.config().yes() { if ctx.config().yes(Step::System) {
command.arg("-y"); command.arg("-y");
} }
command.check_run()?; command.check_run()?;
@@ -391,7 +392,7 @@ fn upgrade_neon(ctx: &ExecutionContext) -> Result<()> {
ctx.run_type().execute(&sudo).arg(&pkcon).arg("refresh").check_run()?; ctx.run_type().execute(&sudo).arg(&pkcon).arg("refresh").check_run()?;
let mut exe = ctx.run_type().execute(&sudo); let mut exe = ctx.run_type().execute(&sudo);
let cmd = exe.arg(&pkcon).arg("update"); let cmd = exe.arg(&pkcon).arg("update");
if ctx.config().yes() { if ctx.config().yes(Step::System) {
cmd.arg("-y"); cmd.arg("-y");
} }
if ctx.config().cleanup() { if ctx.config().cleanup() {
@@ -438,7 +439,7 @@ pub fn run_fwupdmgr(ctx: &ExecutionContext) -> Result<()> {
if ctx.config().firmware_upgrade() { if ctx.config().firmware_upgrade() {
updmgr.arg("update"); updmgr.arg("update");
if ctx.config().yes() { if ctx.config().yes(Step::System) {
updmgr.arg("-y"); updmgr.arg("-y");
} }
} else { } else {

View File

@@ -1,7 +1,7 @@
use crate::execution_context::ExecutionContext; use crate::execution_context::ExecutionContext;
use crate::executor::RunType; use crate::executor::RunType;
use crate::terminal::{print_separator, prompt_yesno}; use crate::terminal::{print_separator, prompt_yesno};
use crate::{error::TopgradeError, utils::require}; use crate::{error::TopgradeError, utils::require, Step};
use anyhow::Result; use anyhow::Result;
use log::debug; use log::debug;
use std::process::Command; use std::process::Command;
@@ -42,7 +42,7 @@ pub fn run_silnite(ctx: &ExecutionContext) -> Result<()> {
pub fn upgrade_macos(ctx: &ExecutionContext) -> Result<()> { pub fn upgrade_macos(ctx: &ExecutionContext) -> Result<()> {
print_separator("macOS system update"); print_separator("macOS system update");
let should_ask = !(ctx.config().yes()) || (ctx.config().dry_run()); let should_ask = !(ctx.config().yes(Step::System)) || (ctx.config().dry_run());
if should_ask { if should_ask {
println!("Finding available software"); println!("Finding available software");
if system_update_available()? { if system_update_available()? {

View File

@@ -7,6 +7,7 @@ use crate::executor::CommandExt;
use crate::executor::{Executor, ExecutorExitStatus, RunType}; use crate::executor::{Executor, ExecutorExitStatus, RunType};
use crate::terminal::{print_separator, print_warning}; use crate::terminal::{print_separator, print_warning};
use crate::utils::{require, require_option, PathExt}; use crate::utils::{require, require_option, PathExt};
use crate::Step;
use anyhow::Result; use anyhow::Result;
use directories::BaseDirs; use directories::BaseDirs;
use log::debug; use log::debug;
@@ -106,14 +107,14 @@ pub fn run_pkgin(ctx: &ExecutionContext) -> Result<()> {
let mut command = ctx.run_type().execute(ctx.sudo().as_ref().unwrap()); let mut command = ctx.run_type().execute(ctx.sudo().as_ref().unwrap());
command.arg(&pkgin).arg("update"); command.arg(&pkgin).arg("update");
if ctx.config().yes() { if ctx.config().yes(Step::Pkgin) {
command.arg("-y"); command.arg("-y");
} }
command.check_run()?; command.check_run()?;
let mut command = ctx.run_type().execute(ctx.sudo().as_ref().unwrap()); let mut command = ctx.run_type().execute(ctx.sudo().as_ref().unwrap());
command.arg(&pkgin).arg("upgrade"); command.arg(&pkgin).arg("upgrade");
if ctx.config().yes() { if ctx.config().yes(Step::Pkgin) {
command.arg("-y"); command.arg("-y");
} }
command.check_run() command.check_run()

View File

@@ -1,18 +1,20 @@
use crate::execution_context::ExecutionContext;
use crate::executor::{CommandExt, RunType};
use crate::powershell;
use crate::terminal::print_separator;
use crate::utils::require;
use crate::{error::SkipStep, steps::git::Repositories};
use anyhow::Result;
use log::debug;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::path::Path; use std::path::Path;
use std::{ffi::OsStr, process::Command}; use std::{ffi::OsStr, process::Command};
use anyhow::Result;
use log::debug;
use crate::execution_context::ExecutionContext;
use crate::executor::{CommandExt, RunType};
use crate::terminal::print_separator;
use crate::utils::require;
use crate::{error::SkipStep, steps::git::Repositories};
use crate::{powershell, Step};
pub fn run_chocolatey(ctx: &ExecutionContext) -> Result<()> { pub fn run_chocolatey(ctx: &ExecutionContext) -> Result<()> {
let choco = require("choco")?; let choco = require("choco")?;
let yes = ctx.config().yes(); let yes = ctx.config().yes(Step::Chocolatey);
print_separator("Chocolatey"); print_separator("Chocolatey");
@@ -70,7 +72,7 @@ pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> {
.args(&["bash", "-c"]) .args(&["bash", "-c"])
.arg(format!("TOPGRADE_PREFIX=WSL exec {}", topgrade)); .arg(format!("TOPGRADE_PREFIX=WSL exec {}", topgrade));
if ctx.config().yes() { if ctx.config().yes(Step::Wsl) {
command.arg("-y"); command.arg("-y");
} }

View File

@@ -1,13 +1,16 @@
use crate::execution_context::ExecutionContext;
use crate::executor::CommandExt;
use crate::terminal::{is_dumb, print_separator};
use crate::utils::{require_option, which, PathExt};
use anyhow::Result;
#[cfg(windows)] #[cfg(windows)]
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use anyhow::Result;
use crate::execution_context::ExecutionContext;
use crate::executor::CommandExt;
use crate::terminal::{is_dumb, print_separator};
use crate::utils::{require_option, which, PathExt};
use crate::Step;
pub struct Powershell { pub struct Powershell {
path: Option<PathBuf>, path: Option<PathBuf>,
profile: Option<PathBuf>, profile: Option<PathBuf>,
@@ -69,7 +72,7 @@ impl Powershell {
cmd.push("-Verbose") cmd.push("-Verbose")
} }
if ctx.config().yes() { if ctx.config().yes(Step::Powershell) {
cmd.push("-Confirm") cmd.push("-Confirm")
} }

View File

@@ -1,6 +1,7 @@
use crate::{error::SkipStep, execution_context::ExecutionContext, terminal::print_separator, utils};
use anyhow::Result; use anyhow::Result;
use crate::{error::SkipStep, execution_context::ExecutionContext, terminal::print_separator, utils};
fn prepare_async_ssh_command(args: &mut Vec<&str>) { fn prepare_async_ssh_command(args: &mut Vec<&str>) {
args.insert(0, "ssh"); args.insert(0, "ssh");
args.push("--keep"); args.push("--keep");
@@ -19,10 +20,6 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
let env = format!("TOPGRADE_PREFIX={}", hostname); let env = format!("TOPGRADE_PREFIX={}", hostname);
args.extend(&["env", &env, "$SHELL", "-lc", topgrade]); args.extend(&["env", &env, "$SHELL", "-lc", topgrade]);
if ctx.config().yes() {
args.push("-y");
}
if ctx.config().run_in_tmux() && !ctx.run_type().dry() { if ctx.config().run_in_tmux() && !ctx.run_type().dry() {
#[cfg(unix)] #[cfg(unix)]
{ {
@@ -47,10 +44,6 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
let env = format!("TOPGRADE_PREFIX={}", hostname); let env = format!("TOPGRADE_PREFIX={}", hostname);
args.extend(&["env", &env, "$SHELL", "-lc", topgrade]); args.extend(&["env", &env, "$SHELL", "-lc", topgrade]);
if ctx.config().yes() {
args.push("-y");
}
print_separator(format!("Remote ({})", hostname)); print_separator(format!("Remote ({})", hostname));
println!("Connecting to {}...", hostname); println!("Connecting to {}...", hostname);

View File

@@ -1,14 +1,16 @@
use crate::execution_context::ExecutionContext;
use crate::executor::CommandExt;
use crate::terminal::print_separator;
use crate::{error::SkipStep, utils};
use anyhow::Result;
use log::{debug, error};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use std::{fmt::Display, rc::Rc, str::FromStr}; use std::{fmt::Display, rc::Rc, str::FromStr};
use anyhow::Result;
use log::{debug, error};
use strum::EnumString; use strum::EnumString;
use crate::execution_context::ExecutionContext;
use crate::executor::CommandExt;
use crate::terminal::print_separator;
use crate::{error::SkipStep, utils, Step};
#[derive(Debug, Copy, Clone, EnumString)] #[derive(Debug, Copy, Clone, EnumString)]
#[strum(serialize_all = "lowercase")] #[strum(serialize_all = "lowercase")]
enum BoxStatus { enum BoxStatus {
@@ -188,7 +190,7 @@ pub fn topgrade_vagrant_box(ctx: &ExecutionContext, vagrant_box: &VagrantBox) ->
print_separator(seperator); print_separator(seperator);
} }
let mut command = format!("env TOPGRADE_PREFIX={} topgrade", vagrant_box.smart_name()); let mut command = format!("env TOPGRADE_PREFIX={} topgrade", vagrant_box.smart_name());
if ctx.config().yes() { if ctx.config().yes(Step::Vagrant) {
command.push_str(" -y"); command.push_str(" -y");
} }