Add quiet option (which may still be quite noisy)

This commit is contained in:
Zykino 2023-01-16 22:51:33 +01:00
parent 0eb443976f
commit 088eb42521
3 changed files with 23 additions and 16 deletions

View File

@ -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 users 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);
}

View File

@ -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>>,
}

View File

@ -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);
}