Skip to content

Commit

Permalink
Merge pull request #168 from azriel91/feature/167/toggle-progress-bar…
Browse files Browse the repository at this point in the history
…s-per-command
  • Loading branch information
azriel91 authored Dec 29, 2023
2 parents 1a1653f + 040d483 commit 3c85023
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 42 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
* 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
[#141]: https://github.com/azriel91/peace/issues/141
[#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)
Expand Down
17 changes: 9 additions & 8 deletions crate/rt/src/cmds/diff_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 9 additions & 8 deletions crate/rt/src/cmds/states_current_read_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ where
pub async fn exec<'ctx>(
cmd_ctx: &mut CmdCtx<SingleProfileSingleFlow<'ctx, E, O, PKeys, SetUp>>,
) -> Result<CmdOutcome<StatesCurrentStored, E>, E> {
CmdExecution::<StatesCurrentStored, _, _>::builder()
.with_cmd_block(CmdBlockWrapper::new(
StatesCurrentReadCmdBlock::new(),
std::convert::identity,
))
.build()
.exec(cmd_ctx)
.await
let cmd_execution_builder =
CmdExecution::<StatesCurrentStored, _, _>::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
}
}

Expand Down
12 changes: 7 additions & 5 deletions crate/rt/src/cmds/states_goal_read_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ where
pub async fn exec<'ctx>(
cmd_ctx: &mut CmdCtx<SingleProfileSingleFlow<'ctx, E, O, PKeys, SetUp>>,
) -> Result<CmdOutcome<StatesGoalStored, E>, E> {
CmdExecution::<StatesGoalStored, _, _>::builder()
let cmd_execution_builder = CmdExecution::<StatesGoalStored, _, _>::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
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/envman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ js-sys = "0.3.66"
web-sys = "0.3.66"

[features]
default = []
default = ["cli"]

# === envman modes === #
cli = [
Expand Down
2 changes: 2 additions & 0 deletions examples/envman/src/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions examples/envman/src/cmds/app_upload_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use peace::{
};

use crate::{
cmds::CmdOpts,
flows::AppUploadFlow,
items::{
peace_aws_s3_bucket::S3BucketState,
Expand All @@ -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<O, T, F>(output: &mut O, profile_print: bool, f: F) -> Result<T, EnvManError>
pub async fn run<O, T, F>(output: &mut O, cmd_opts: CmdOpts, f: F) -> Result<T, EnvManError>
where
O: OutputWrite<EnvManError>,
for<'fn_once> F: FnOnce(
Expand Down Expand Up @@ -82,6 +83,8 @@ impl AppUploadCmd {
.await?
};

let CmdOpts { profile_print } = cmd_opts;

if profile_print {
Self::profile_print(&mut cmd_ctx).await?;
}
Expand Down
22 changes: 22 additions & 0 deletions examples/envman/src/cmds/cmd_opts.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
10 changes: 6 additions & 4 deletions examples/envman/src/cmds/env_clean_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?;
}};
}
Expand Down
7 changes: 5 additions & 2 deletions examples/envman/src/cmds/env_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use peace::{
};

use crate::{
cmds::CmdOpts,
flows::EnvDeployFlow,
items::{
peace_aws_iam_policy::IamPolicyState,
Expand All @@ -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<O, T, F>(output: &mut O, profile_print: bool, f: F) -> Result<T, EnvManError>
pub async fn run<O, T, F>(output: &mut O, cmd_opts: CmdOpts, f: F) -> Result<T, EnvManError>
where
O: OutputWrite<EnvManError>,
for<'fn_once> F: FnOnce(
Expand Down Expand Up @@ -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::<EnvManError, _>(output, &workspace);
Expand Down
10 changes: 6 additions & 4 deletions examples/envman/src/cmds/env_deploy_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?;
}};
}
Expand Down
4 changes: 2 additions & 2 deletions examples/envman/src/cmds/env_diff_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use peace::{
use crate::{
cmds::{
common::{env_man_flow, workspace},
AppUploadCmd, EnvCmd,
AppUploadCmd, CmdOpts, EnvCmd,
},
model::{EnvDiffSelection, EnvManError, EnvManFlow},
};
Expand Down Expand Up @@ -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?;

Expand Down
4 changes: 2 additions & 2 deletions examples/envman/src/cmds/env_discover_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?;
Expand Down
4 changes: 2 additions & 2 deletions examples/envman/src/cmds/env_goal_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?;
Expand Down
4 changes: 2 additions & 2 deletions examples/envman/src/cmds/env_status_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?;
Expand Down

0 comments on commit 3c85023

Please sign in to comment.