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