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:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2

View File

@@ -393,9 +393,9 @@ pub struct CommandLineArgs {
#[structopt(short = "k", long = "keep")]
keep_at_end: bool,
/// Say yes to package manager's prompt (experimental)
/// Say yes to package manager's prompt
#[structopt(short = "y", long = "yes")]
yes: bool,
yes: Option<Vec<Step>>,
/// Don't pull the predefined git repos
#[structopt(long = "disable-predefined-git-repos")]
@@ -585,8 +585,20 @@ impl Config {
/// Whether to say yes to package managers
#[allow(dead_code)]
pub fn yes(&self) -> bool {
self.config_file.assume_yes.unwrap_or(self.opt.yes)
pub fn yes(&self, step: Step) -> bool {
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

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"))]
use std::env;
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");
#[cfg(windows)]
const DOOM_PATH: &str = "bin/doom.cmd";
@@ -66,7 +69,7 @@ impl Emacs {
let mut command = ctx.run_type().execute(doom);
command.args(&["-y", "upgrade"]);
if ctx.config().yes() {
if ctx.config().yes(Step::Emacs) {
command.arg("--force");
}

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
use crate::execution_context::ExecutionContext;
use crate::executor::RunType;
use crate::terminal::{print_separator, prompt_yesno};
use crate::{error::TopgradeError, utils::require};
use crate::{error::TopgradeError, utils::require, Step};
use anyhow::Result;
use log::debug;
use std::process::Command;
@@ -42,7 +42,7 @@ pub fn run_silnite(ctx: &ExecutionContext) -> Result<()> {
pub fn upgrade_macos(ctx: &ExecutionContext) -> Result<()> {
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 {
println!("Finding available software");
if system_update_available()? {

View File

@@ -7,6 +7,7 @@ use crate::executor::CommandExt;
use crate::executor::{Executor, ExecutorExitStatus, RunType};
use crate::terminal::{print_separator, print_warning};
use crate::utils::{require, require_option, PathExt};
use crate::Step;
use anyhow::Result;
use directories::BaseDirs;
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());
command.arg(&pkgin).arg("update");
if ctx.config().yes() {
if ctx.config().yes(Step::Pkgin) {
command.arg("-y");
}
command.check_run()?;
let mut command = ctx.run_type().execute(ctx.sudo().as_ref().unwrap());
command.arg(&pkgin).arg("upgrade");
if ctx.config().yes() {
if ctx.config().yes(Step::Pkgin) {
command.arg("-y");
}
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::path::Path;
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<()> {
let choco = require("choco")?;
let yes = ctx.config().yes();
let yes = ctx.config().yes(Step::Chocolatey);
print_separator("Chocolatey");
@@ -70,7 +72,7 @@ pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> {
.args(&["bash", "-c"])
.arg(format!("TOPGRADE_PREFIX=WSL exec {}", topgrade));
if ctx.config().yes() {
if ctx.config().yes(Step::Wsl) {
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)]
use std::path::Path;
use std::path::PathBuf;
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 {
path: Option<PathBuf>,
profile: Option<PathBuf>,
@@ -69,7 +72,7 @@ impl Powershell {
cmd.push("-Verbose")
}
if ctx.config().yes() {
if ctx.config().yes(Step::Powershell) {
cmd.push("-Confirm")
}

View File

@@ -1,6 +1,7 @@
use crate::{error::SkipStep, execution_context::ExecutionContext, terminal::print_separator, utils};
use anyhow::Result;
use crate::{error::SkipStep, execution_context::ExecutionContext, terminal::print_separator, utils};
fn prepare_async_ssh_command(args: &mut Vec<&str>) {
args.insert(0, "ssh");
args.push("--keep");
@@ -19,10 +20,6 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
let env = format!("TOPGRADE_PREFIX={}", hostname);
args.extend(&["env", &env, "$SHELL", "-lc", topgrade]);
if ctx.config().yes() {
args.push("-y");
}
if ctx.config().run_in_tmux() && !ctx.run_type().dry() {
#[cfg(unix)]
{
@@ -47,10 +44,6 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
let env = format!("TOPGRADE_PREFIX={}", hostname);
args.extend(&["env", &env, "$SHELL", "-lc", topgrade]);
if ctx.config().yes() {
args.push("-y");
}
print_separator(format!("Remote ({})", 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::process::Command;
use std::{fmt::Display, rc::Rc, str::FromStr};
use anyhow::Result;
use log::{debug, error};
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)]
#[strum(serialize_all = "lowercase")]
enum BoxStatus {
@@ -188,7 +190,7 @@ pub fn topgrade_vagrant_box(ctx: &ExecutionContext, vagrant_box: &VagrantBox) ->
print_separator(seperator);
}
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");
}