Add quiet option (which may still be quite noisy)
This commit is contained in:
		@@ -4,7 +4,7 @@ use std::collections::HashMap;
 | 
			
		||||
use std::fmt;
 | 
			
		||||
use std::io::{stdout, Write};
 | 
			
		||||
use std::path::PathBuf;
 | 
			
		||||
use std::process::Command;
 | 
			
		||||
use std::process::{Command, Stdio};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
 | 
			
		||||
enum UpdateSteps {
 | 
			
		||||
@@ -213,12 +213,7 @@ impl ActualCmd {
 | 
			
		||||
    fn execute(&self, opt: &Opt) -> Result<bool> {
 | 
			
		||||
        let mut cmd = Command::new(&self.exe);
 | 
			
		||||
 | 
			
		||||
        cmd.args(&self.params)
 | 
			
		||||
            .env_clear()
 | 
			
		||||
            .envs(&self.env)
 | 
			
		||||
            // .stdout(cfg)
 | 
			
		||||
            // .stderr(cfg)
 | 
			
		||||
            ;
 | 
			
		||||
        cmd.args(&self.params).env_clear().envs(&self.env);
 | 
			
		||||
 | 
			
		||||
        if let Some(cdir) = &self.current_dir {
 | 
			
		||||
            cmd.current_dir(std::fs::canonicalize(cdir).unwrap());
 | 
			
		||||
@@ -229,19 +224,26 @@ impl ActualCmd {
 | 
			
		||||
        print!("Will execute {}{}", self, confirm);
 | 
			
		||||
        stdout().flush().unwrap();
 | 
			
		||||
 | 
			
		||||
        let mut yes_no = String::new();
 | 
			
		||||
        if opt.quiet {
 | 
			
		||||
            // Maybe we should only hide with the quiet option and not with yes?
 | 
			
		||||
            // FIXME: stdin does not work with sudo?
 | 
			
		||||
            cmd.stdin(Stdio::null())
 | 
			
		||||
                .stdout(Stdio::null())
 | 
			
		||||
                .stderr(Stdio::null());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let mut user_continue = String::new();
 | 
			
		||||
        if !opt.yes {
 | 
			
		||||
            std::io::stdin()
 | 
			
		||||
                .read_line(&mut yes_no)
 | 
			
		||||
                .read_line(&mut user_continue)
 | 
			
		||||
                .expect("Unable to read user’s input");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if yes_no.to_lowercase().starts_with('n') {
 | 
			
		||||
        if user_continue.to_lowercase().starts_with('n') {
 | 
			
		||||
            eprintln!(
 | 
			
		||||
                "yes_no? {} {}",
 | 
			
		||||
                yes_no,
 | 
			
		||||
                yes_no.to_lowercase().starts_with('n')
 | 
			
		||||
                "user_continue? {} {}",
 | 
			
		||||
                user_continue,
 | 
			
		||||
                user_continue.to_lowercase().starts_with('n')
 | 
			
		||||
            );
 | 
			
		||||
            return Ok(false);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -23,9 +23,11 @@ pub struct Opt {
 | 
			
		||||
    //#[arg(default_value_t = PathBuf::from("examples/debian.yml"))]
 | 
			
		||||
    pub config_file: PathBuf,
 | 
			
		||||
 | 
			
		||||
    #[arg(short)]
 | 
			
		||||
    #[arg(short, long)]
 | 
			
		||||
    pub yes: bool,
 | 
			
		||||
    //pub quiet: bool, // imply yes
 | 
			
		||||
 | 
			
		||||
    #[arg(short, long)]
 | 
			
		||||
    pub quiet: bool,
 | 
			
		||||
    #[arg(short, long)]
 | 
			
		||||
    pub steps: Option<Vec<String>>,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,10 @@ use clap::Parser;
 | 
			
		||||
use system_updater::*;
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    let opt = Opt::parse();
 | 
			
		||||
    let mut opt = Opt::parse();
 | 
			
		||||
    if opt.quiet {
 | 
			
		||||
        opt.yes = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    run(&opt);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user