Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow running workflows with input from stdin #414

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 logic: Consider handling the potential error from find_workflow_file_from instead of using 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
}
}
}
Loading