diff --git a/fud2/fud-core/src/cli.rs b/fud2/fud-core/src/cli.rs index cc9645808..2743b6581 100644 --- a/fud2/fud-core/src/cli.rs +++ b/fud2/fud-core/src/cli.rs @@ -142,7 +142,7 @@ pub enum Subcommand { #[derive(FromArgs)] /// A generic compiler driver. -pub struct FakeArgs { +pub struct FudArgs { #[argh(subcommand)] pub sub: Option>, @@ -190,6 +190,10 @@ pub struct FakeArgs { #[argh(switch, short = 'v')] verbose: Option, + /// quiet mode + #[argh(switch, short = 'q')] + quiet: bool, + /// log level for debugging fud internal #[argh(option, long = "log", default = "log::LevelFilter::Warn")] pub log_level: log::LevelFilter, @@ -229,7 +233,7 @@ fn get_states_with_errors( fn from_states( driver: &Driver, - args: &FakeArgs, + args: &FudArgs, ) -> anyhow::Result> { get_states_with_errors( driver, @@ -243,7 +247,7 @@ fn from_states( fn to_state( driver: &Driver, - args: &FakeArgs, + args: &FudArgs, ) -> anyhow::Result> { get_states_with_errors( driver, @@ -257,7 +261,7 @@ fn to_state( fn get_request( driver: &Driver, - args: &FakeArgs, + args: &FudArgs, ) -> anyhow::Result { // The default working directory (if not specified) depends on the mode. let workdir = args.dir.clone().unwrap_or_else(|| match args.mode { @@ -407,7 +411,7 @@ impl CliStart for T { fn config_from_cli_ext( name: &str, ) -> anyhow::Result { - let args: FakeArgs = argh::from_env(); + let args: FudArgs = argh::from_env(); let mut config = config::load_config(name); // Use `--set` arguments to override configuration values. @@ -428,7 +432,7 @@ fn cli_ext( driver: &Driver, config: &figment::Figment, ) -> anyhow::Result<()> { - let args: FakeArgs = argh::from_env(); + let args: FudArgs = argh::from_env(); // Configure logging. env_logger::Builder::new() .format_timestamp(None) @@ -479,8 +483,8 @@ fn cli_ext( Mode::ShowDot => run.show_dot(), Mode::EmitNinja => run.emit_to_stdout()?, Mode::Generate => run.emit_to_dir(&workdir)?.keep(), - Mode::Run => run.emit_and_run(&workdir, false)?, - Mode::Cmds => run.emit_and_run(&workdir, true)?, + Mode::Run => run.emit_and_run(&workdir, false, args.quiet)?, + Mode::Cmds => run.emit_and_run(&workdir, true, false)?, } Ok(()) diff --git a/fud2/fud-core/src/run.rs b/fud2/fud-core/src/run.rs index c61993e80..a77d8e8fe 100644 --- a/fud2/fud-core/src/run.rs +++ b/fud2/fud-core/src/run.rs @@ -339,7 +339,12 @@ impl<'a> Run<'a> { /// Emit `build.ninja` to a temporary directory and then actually execute Ninja. /// /// If `print_cmds` is true, Ninja will print commands it is to run instead of executing them. - pub fn emit_and_run(&self, dir: &Utf8Path, print_cmds: bool) -> EmitResult { + pub fn emit_and_run( + &self, + dir: &Utf8Path, + print_cmds: bool, + quiet_mode: bool, + ) -> EmitResult { // Emit the Ninja file. let dir = self.emit_to_dir(dir)?; @@ -375,7 +380,11 @@ impl<'a> Run<'a> { cmd.arg("-tcommands"); } - cmd.stdout(std::io::stderr()); // Send Ninja's stdout to our stderr. + if !quiet_mode { + cmd.stdout(std::io::stderr()); // Send Ninja's stdout to our stderr. + } else { + cmd.stdout(std::process::Stdio::null()); + } let status = cmd.status().map_err(ninja_cmd_io_error)?; // Emit to stdout, only when Ninja succeeded.