Skip to content

Commit

Permalink
feat: allow running workflows with input from stdin (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Jul 11, 2024
1 parent f1dedc0 commit 85e4227
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/cli/src/commands/apply_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct ApplyMigrationArgs {
help_heading = "Workflow options",
help = "JSON input parameter to pass to the workflow"
)]
input: Option<String>,
pub(crate) input: Option<String>,
#[clap(
long,
help_heading = "Workflow options",
Expand All @@ -31,7 +31,7 @@ pub struct ApplyMigrationArgs {
pub(crate) remote: bool,
/// Print verbose output
#[clap(long)]
verbose: bool,
pub(crate) verbose: bool,
}

impl ApplyMigrationArgs {
Expand Down
38 changes: 38 additions & 0 deletions crates/cli/src/commands/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use marzano_gritmodule::searcher::find_grit_modules_dir;
use marzano_gritmodule::utils::is_pattern_name;
use marzano_messenger::emit::ApplyDetails;
use serde::{Deserialize, Serialize};
use std::env::current_dir;
use std::io::{stdin, Read};
use std::path::Path;
use std::path::PathBuf;
Expand Down Expand Up @@ -92,6 +93,14 @@ pub enum PlumbingArgs {
#[command(flatten)]
shared_args: SharedPlumbingArgs,
},
/// Run a workflow
#[cfg(feature = "workflows_v2")]
Run {
#[command(flatten)]
shared_args: SharedPlumbingArgs,
/// Workflow definition file
definition: String,
},
}

fn read_input(shared_args: &SharedPlumbingArgs) -> Result<String> {
Expand Down Expand Up @@ -281,5 +290,34 @@ pub(crate) async fn run_plumbing(
super::patterns_test::AggregatedTestResult::AllPassed => Ok(()),
}
}
#[cfg(feature = "workflows_v2")]
PlumbingArgs::Run {
shared_args,
definition,
} => {
let buffer = read_input(&shared_args)?;

let current_dir = current_dir()?;

let custom_workflow = marzano_gritmodule::searcher::find_workflow_file_from(
current_dir.clone(),
&definition,
)
.await
.unwrap();

super::apply_migration::run_apply_migration(
custom_workflow,
vec![current_dir],
None,
super::apply_migration::ApplyMigrationArgs {
input: Some(buffer),
remote: false,
verbose: true,
},
&parent,
)
.await
}
}
}

0 comments on commit 85e4227

Please sign in to comment.