diff --git a/CHANGELOG.md b/CHANGELOG.md index 95409eca6..98b10c4dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Add `CmdBlock` trait to encompass one function for all items. ([#141], [#163]) * Add interruptibility support using [`interruptible`] through `CmdCtxBuilder::with_interruptibility`. ([#141], [#163]) * Add `ItemStreamOutcome` to track which `Item`s are processed or not processed. ([#164], [#165]) +* Suppress progress rendering for `StatesCurrentReadCmd`, `StatesGoalReadCmd`, and `DiffCmd`. ([#167], [#168]) [`interruptible`]: https://github.com/azriel91/interruptible @@ -13,6 +14,8 @@ [#163]: https://github.com/azriel91/peace/pull/163 [#164]: https://github.com/azriel91/peace/issues/164 [#165]: https://github.com/azriel91/peace/pull/165 +[#167]: https://github.com/azriel91/peace/issues/167 +[#168]: https://github.com/azriel91/peace/pull/168 ## 0.0.11 (2023-06-27) diff --git a/crate/rt/src/cmds/diff_cmd.rs b/crate/rt/src/cmds/diff_cmd.rs index 0637def7e..27276abf9 100644 --- a/crate/rt/src/cmds/diff_cmd.rs +++ b/crate/rt/src/cmds/diff_cmd.rs @@ -93,14 +93,15 @@ where StatesTs1::diff_state_spec(), ); - let mut cmd_execution = cmd_execution_builder - .with_cmd_block(CmdBlockWrapper::new( - DiffCmdBlock::<_, _, StatesTs0, StatesTs1>::new(), - |_state_diffs_ts0_and_ts1| StateDiffs::new(), - )) - .build(); - - cmd_execution.exec(cmd_ctx).await + cmd_execution_builder = cmd_execution_builder.with_cmd_block(CmdBlockWrapper::new( + DiffCmdBlock::<_, _, StatesTs0, StatesTs1>::new(), + |_state_diffs_ts0_and_ts1| StateDiffs::new(), + )); + + #[cfg(feature = "output_progress")] + let cmd_execution_builder = cmd_execution_builder.with_progress_render_enabled(false); + + cmd_execution_builder.build().exec(cmd_ctx).await } fn states_fetch_cmd_block_append( diff --git a/crate/rt/src/cmds/states_current_read_cmd.rs b/crate/rt/src/cmds/states_current_read_cmd.rs index d45949513..c1316490d 100644 --- a/crate/rt/src/cmds/states_current_read_cmd.rs +++ b/crate/rt/src/cmds/states_current_read_cmd.rs @@ -29,14 +29,15 @@ where pub async fn exec<'ctx>( cmd_ctx: &mut CmdCtx>, ) -> Result, E> { - CmdExecution::::builder() - .with_cmd_block(CmdBlockWrapper::new( - StatesCurrentReadCmdBlock::new(), - std::convert::identity, - )) - .build() - .exec(cmd_ctx) - .await + let cmd_execution_builder = + CmdExecution::::builder().with_cmd_block( + CmdBlockWrapper::new(StatesCurrentReadCmdBlock::new(), std::convert::identity), + ); + + #[cfg(feature = "output_progress")] + let cmd_execution_builder = cmd_execution_builder.with_progress_render_enabled(false); + + cmd_execution_builder.build().exec(cmd_ctx).await } } diff --git a/crate/rt/src/cmds/states_goal_read_cmd.rs b/crate/rt/src/cmds/states_goal_read_cmd.rs index d27ab682d..f031e3fc0 100644 --- a/crate/rt/src/cmds/states_goal_read_cmd.rs +++ b/crate/rt/src/cmds/states_goal_read_cmd.rs @@ -28,14 +28,16 @@ where pub async fn exec<'ctx>( cmd_ctx: &mut CmdCtx>, ) -> Result, E> { - CmdExecution::::builder() + let cmd_execution_builder = CmdExecution::::builder() .with_cmd_block(CmdBlockWrapper::new( StatesGoalReadCmdBlock::new(), std::convert::identity, - )) - .build() - .exec(cmd_ctx) - .await + )); + + #[cfg(feature = "output_progress")] + let cmd_execution_builder = cmd_execution_builder.with_progress_render_enabled(false); + + cmd_execution_builder.build().exec(cmd_ctx).await } } diff --git a/examples/envman/Cargo.toml b/examples/envman/Cargo.toml index 196c2d357..09b5c7e8f 100644 --- a/examples/envman/Cargo.toml +++ b/examples/envman/Cargo.toml @@ -65,7 +65,7 @@ js-sys = "0.3.66" web-sys = "0.3.66" [features] -default = [] +default = ["cli"] # === envman modes === # cli = [ diff --git a/examples/envman/src/cmds.rs b/examples/envman/src/cmds.rs index d5751b9c1..2e9f739b6 100644 --- a/examples/envman/src/cmds.rs +++ b/examples/envman/src/cmds.rs @@ -9,6 +9,7 @@ pub use self::{ app_upload_cmd::AppUploadCmd, cmd_ctx_builder::{interruptibility_augment, ws_and_profile_params_augment, ws_params_augment}, + cmd_opts::CmdOpts, env_clean_cmd::EnvCleanCmd, env_cmd::EnvCmd, env_deploy_cmd::EnvDeployCmd, @@ -24,6 +25,7 @@ pub use self::{ mod app_upload_cmd; mod cmd_ctx_builder; +mod cmd_opts; mod common; mod env_clean_cmd; mod env_cmd; diff --git a/examples/envman/src/cmds/app_upload_cmd.rs b/examples/envman/src/cmds/app_upload_cmd.rs index 4471b9cd1..0a95128df 100644 --- a/examples/envman/src/cmds/app_upload_cmd.rs +++ b/examples/envman/src/cmds/app_upload_cmd.rs @@ -19,6 +19,7 @@ use peace::{ }; use crate::{ + cmds::CmdOpts, flows::AppUploadFlow, items::{ peace_aws_s3_bucket::S3BucketState, @@ -38,9 +39,9 @@ impl AppUploadCmd { /// # Parameters /// /// * `output`: Output to write the execution outcome. - /// * `profile_print`: Whether to print the profile used. + /// * `cmd_opts`: Options to configure the `Cmd`'s output. /// * `f`: The command to run. - pub async fn run(output: &mut O, profile_print: bool, f: F) -> Result + pub async fn run(output: &mut O, cmd_opts: CmdOpts, f: F) -> Result where O: OutputWrite, for<'fn_once> F: FnOnce( @@ -82,6 +83,8 @@ impl AppUploadCmd { .await? }; + let CmdOpts { profile_print } = cmd_opts; + if profile_print { Self::profile_print(&mut cmd_ctx).await?; } diff --git a/examples/envman/src/cmds/cmd_opts.rs b/examples/envman/src/cmds/cmd_opts.rs new file mode 100644 index 000000000..7e5db9f19 --- /dev/null +++ b/examples/envman/src/cmds/cmd_opts.rs @@ -0,0 +1,22 @@ +/// Options to configure a `Cmd`'s output. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct CmdOpts { + /// Whether or not to print the active profile. + pub profile_print: bool, +} + +impl CmdOpts { + /// Sets whether or not to print the active profile. + pub fn with_profile_print(mut self, profile_print: bool) -> Self { + self.profile_print = profile_print; + self + } +} + +impl Default for CmdOpts { + fn default() -> Self { + Self { + profile_print: true, + } + } +} diff --git a/examples/envman/src/cmds/env_clean_cmd.rs b/examples/envman/src/cmds/env_clean_cmd.rs index 118a196b0..95532bb44 100644 --- a/examples/envman/src/cmds/env_clean_cmd.rs +++ b/examples/envman/src/cmds/env_clean_cmd.rs @@ -10,7 +10,7 @@ use peace::{ use crate::{ cmds::{ common::{env_man_flow, workspace}, - AppUploadCmd, EnvCmd, + AppUploadCmd, CmdOpts, EnvCmd, }, model::{EnvManError, EnvManFlow}, rt_model::EnvManCmdCtx, @@ -43,9 +43,11 @@ impl EnvCleanCmd { macro_rules! run { ($output:ident, $flow_cmd:ident, $padding:expr) => {{ - $flow_cmd::run($output, false, |cmd_ctx| { - run_with_ctx(cmd_ctx, $padding).boxed_local() - }) + $flow_cmd::run( + $output, + CmdOpts::default().with_profile_print(false), + |cmd_ctx| run_with_ctx(cmd_ctx, $padding).boxed_local(), + ) .await?; }}; } diff --git a/examples/envman/src/cmds/env_cmd.rs b/examples/envman/src/cmds/env_cmd.rs index c7757d9db..d0926eca1 100644 --- a/examples/envman/src/cmds/env_cmd.rs +++ b/examples/envman/src/cmds/env_cmd.rs @@ -19,6 +19,7 @@ use peace::{ }; use crate::{ + cmds::CmdOpts, flows::EnvDeployFlow, items::{ peace_aws_iam_policy::IamPolicyState, @@ -38,9 +39,9 @@ impl EnvCmd { /// # Parameters /// /// * `output`: Output to write the execution outcome. - /// * `profile_print`: Whether to print the profile used. + /// * `cmd_opts`: Options to configure the `Cmd`'s output. /// * `f`: The command to run. - pub async fn run(output: &mut O, profile_print: bool, f: F) -> Result + pub async fn run(output: &mut O, cmd_opts: CmdOpts, f: F) -> Result where O: OutputWrite, for<'fn_once> F: FnOnce( @@ -73,6 +74,8 @@ impl EnvCmd { }) .build(); + let CmdOpts { profile_print } = cmd_opts; + let mut cmd_ctx = { let cmd_ctx_builder = CmdCtx::builder_single_profile_single_flow::(output, &workspace); diff --git a/examples/envman/src/cmds/env_deploy_cmd.rs b/examples/envman/src/cmds/env_deploy_cmd.rs index 76012ff49..b9edf68e9 100644 --- a/examples/envman/src/cmds/env_deploy_cmd.rs +++ b/examples/envman/src/cmds/env_deploy_cmd.rs @@ -10,7 +10,7 @@ use peace::{ use crate::{ cmds::{ common::{env_man_flow, workspace}, - AppUploadCmd, EnvCmd, + AppUploadCmd, CmdOpts, EnvCmd, }, model::{EnvManError, EnvManFlow}, rt_model::EnvManCmdCtx, @@ -43,9 +43,11 @@ impl EnvDeployCmd { macro_rules! run { ($output:ident, $flow_cmd:ident, $padding:expr) => {{ - $flow_cmd::run($output, false, |cmd_ctx| { - run_with_ctx(cmd_ctx, $padding).boxed_local() - }) + $flow_cmd::run( + $output, + CmdOpts::default().with_profile_print(false), + |cmd_ctx| run_with_ctx(cmd_ctx, $padding).boxed_local(), + ) .await?; }}; } diff --git a/examples/envman/src/cmds/env_diff_cmd.rs b/examples/envman/src/cmds/env_diff_cmd.rs index 31cf1d9b5..d2955a68b 100644 --- a/examples/envman/src/cmds/env_diff_cmd.rs +++ b/examples/envman/src/cmds/env_diff_cmd.rs @@ -14,7 +14,7 @@ use peace::{ use crate::{ cmds::{ common::{env_man_flow, workspace}, - AppUploadCmd, EnvCmd, + AppUploadCmd, CmdOpts, EnvCmd, }, model::{EnvDiffSelection, EnvManError, EnvManFlow}, }; @@ -126,7 +126,7 @@ impl EnvDiffCmd { macro_rules! run { ($output:ident, $flow_cmd:ident, $padding:expr) => {{ - $flow_cmd::run($output, true, |ctx| { + $flow_cmd::run($output, CmdOpts::default(), |ctx| { async { let state_diffs_outcome = DiffCmd::diff_stored(ctx).await?; diff --git a/examples/envman/src/cmds/env_discover_cmd.rs b/examples/envman/src/cmds/env_discover_cmd.rs index 6285c8909..69169cb7f 100644 --- a/examples/envman/src/cmds/env_discover_cmd.rs +++ b/examples/envman/src/cmds/env_discover_cmd.rs @@ -10,7 +10,7 @@ use peace::{ use crate::{ cmds::{ common::{env_man_flow, workspace}, - AppUploadCmd, EnvCmd, + AppUploadCmd, CmdOpts, EnvCmd, }, model::{EnvManError, EnvManFlow}, rt_model::EnvManCmdCtx, @@ -43,7 +43,7 @@ impl EnvDiscoverCmd { macro_rules! run { ($output:ident, $flow_cmd:ident, $padding:expr) => {{ - $flow_cmd::run($output, true, |cmd_ctx| { + $flow_cmd::run($output, CmdOpts::default(), |cmd_ctx| { run_with_ctx(cmd_ctx, $padding).boxed_local() }) .await?; diff --git a/examples/envman/src/cmds/env_goal_cmd.rs b/examples/envman/src/cmds/env_goal_cmd.rs index 2694c19cd..880460144 100644 --- a/examples/envman/src/cmds/env_goal_cmd.rs +++ b/examples/envman/src/cmds/env_goal_cmd.rs @@ -10,7 +10,7 @@ use peace::{ use crate::{ cmds::{ common::{env_man_flow, workspace}, - AppUploadCmd, EnvCmd, + AppUploadCmd, CmdOpts, EnvCmd, }, model::{EnvManError, EnvManFlow}, rt_model::EnvManCmdCtx, @@ -43,7 +43,7 @@ impl EnvGoalCmd { macro_rules! run { ($output:ident, $flow_cmd:ident, $padding:expr) => {{ - $flow_cmd::run($output, true, |cmd_ctx| { + $flow_cmd::run($output, CmdOpts::default(), |cmd_ctx| { run_with_ctx(cmd_ctx, $padding).boxed_local() }) .await?; diff --git a/examples/envman/src/cmds/env_status_cmd.rs b/examples/envman/src/cmds/env_status_cmd.rs index 313b47065..b8207df0a 100644 --- a/examples/envman/src/cmds/env_status_cmd.rs +++ b/examples/envman/src/cmds/env_status_cmd.rs @@ -10,7 +10,7 @@ use peace::{ use crate::{ cmds::{ common::{env_man_flow, workspace}, - AppUploadCmd, EnvCmd, + AppUploadCmd, CmdOpts, EnvCmd, }, model::{EnvManError, EnvManFlow}, rt_model::EnvManCmdCtx, @@ -43,7 +43,7 @@ impl EnvStatusCmd { macro_rules! run { ($output:ident, $flow_cmd:ident, $padding:expr) => {{ - $flow_cmd::run($output, true, |cmd_ctx| { + $flow_cmd::run($output, CmdOpts::default(), |cmd_ctx| { run_with_ctx(cmd_ctx, $padding).boxed_local() }) .await?;