diff --git a/crates/cli/src/commands/apply_migration.rs b/crates/cli/src/commands/apply_migration.rs index 0097b3977..48b58b838 100644 --- a/crates/cli/src/commands/apply_migration.rs +++ b/crates/cli/src/commands/apply_migration.rs @@ -38,6 +38,9 @@ pub struct ApplyMigrationArgs { /// Print verbose output #[clap(long)] pub(crate) verbose: bool, + // Capture remaining arguments + #[arg(trailing_var_arg = true, allow_hyphen_values = true, index = 2)] + pub(crate) inputs: Vec, } impl ApplyMigrationArgs { @@ -104,3 +107,27 @@ pub(crate) async fn run_apply_migration( Ok(workflow_status.clone()) } + +#[cfg(test)] +mod tests { + use super::*; + use anyhow::Result; + use clap::{Arg, ArgAction, Command, FromArgMatches}; + + #[test] + fn test_arg_parsing() -> Result<()> { + let args = ApplyMigrationArgs::augment_args(Command::new("test")); + + let matches = + args.get_matches_from(vec!["test", "--watch", "--test", "bob", "--suzy=queue"]); + + let apply_args = ApplyMigrationArgs::from_arg_matches(&matches)?; + + println!("{:?}", apply_args); + + // assert_eq!(payload.get("test").unwrap().as_str().unwrap(), "bob"); + // assert_eq!(payload.get("suzy").unwrap().as_str().unwrap(), "queue"); + + Ok(()) + } +} diff --git a/crates/cli/src/commands/plumbing.rs b/crates/cli/src/commands/plumbing.rs index 163a22131..73c549cbd 100644 --- a/crates/cli/src/commands/plumbing.rs +++ b/crates/cli/src/commands/plumbing.rs @@ -372,6 +372,7 @@ pub(crate) async fn run_plumbing( workflow_id: None, verbose: true, watch: false, + inputs: vec![], }, emitter, execution_id.clone(), diff --git a/crates/cli/src/workflows.rs b/crates/cli/src/workflows.rs index ae66fa278..1f3017797 100644 --- a/crates/cli/src/workflows.rs +++ b/crates/cli/src/workflows.rs @@ -107,17 +107,20 @@ where ); } - let auth = updater.get_valid_auth().await.map_err(|_| { - anyhow::anyhow!( + let auth = updater.get_valid_auth().await; + if auth.is_err() { + log::warn!( "No valid authentication token found, please run {}", style("grit auth login").bold().red() - ) - })?; + ); + } - if let Some(username) = auth.get_user_name()? { - if !arg.input.contains_key(GRIT_VCS_USER_NAME) { - arg.input - .insert(GRIT_VCS_USER_NAME.to_string(), username.into()); + if let Ok(ref auth) = auth { + if let Some(username) = auth.get_user_name()? { + if !arg.input.contains_key(GRIT_VCS_USER_NAME) { + arg.input + .insert(GRIT_VCS_USER_NAME.to_string(), username.into()); + } } } @@ -157,11 +160,17 @@ where let mut final_child = child .env(ENV_VAR_GRIT_API_URL, get_grit_api_url()) - .env(ENV_VAR_GRIT_AUTH_TOKEN, auth.access_token) .env(ENV_GRIT_WORKSPACE_ROOT, root) .arg("--file") .arg(&tempfile_path) - .kill_on_drop(true) + .kill_on_drop(true); + + let mut final_child = if let Ok(auth) = auth { + final_child.env(ENV_VAR_GRIT_AUTH_TOKEN, auth.access_token) + } else { + final_child + }; + let mut final_child = final_child .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() diff --git a/crates/cli_bin/tests/workflows.rs b/crates/cli_bin/tests/workflows.rs index d74753339..97137bb7a 100644 --- a/crates/cli_bin/tests/workflows.rs +++ b/crates/cli_bin/tests/workflows.rs @@ -132,3 +132,58 @@ fn applies_user_workflows() -> Result<()> { Ok(()) } + +#[test] +fn run_workflow_input() -> Result<()> { + let (_temp_dir, temp_fixtures_root) = get_fixture("grit_modules", true)?; + + let mut cmd = get_test_cmd()?; + cmd.arg("apply") + .arg("https://storage.googleapis.com/grit-workflows-dev-workflow_definitions/test/hello.js") + .arg("--input") + .arg("{\"query\": \"John\"}") + .current_dir(temp_fixtures_root); + + let output = cmd.output()?; + println!("stdout: {:?}", String::from_utf8(output.stdout.clone())?); + println!("stderr: {:?}", String::from_utf8(output.stderr.clone())?); + + assert!( + output.status.success(), + "Command didn't finish successfully" + ); + + let stdout = String::from_utf8(output.stdout)?; + assert!(stdout.contains("Running hello workflow"),); + + assert!(stdout.contains("John as the query")); + + Ok(()) +} + +#[test] +fn run_workflow_arg_input() -> Result<()> { + let (_temp_dir, temp_fixtures_root) = get_fixture("grit_modules", true)?; + + let mut cmd = get_test_cmd()?; + cmd.arg("apply") + .arg("https://storage.googleapis.com/grit-workflows-dev-workflow_definitions/test/hello.js") + .arg("--query=John") + .current_dir(temp_fixtures_root); + + let output = cmd.output()?; + println!("stdout: {:?}", String::from_utf8(output.stdout.clone())?); + println!("stderr: {:?}", String::from_utf8(output.stderr.clone())?); + + assert!( + output.status.success(), + "Command didn't finish successfully" + ); + + let stdout = String::from_utf8(output.stdout)?; + assert!(stdout.contains("Running hello workflow"),); + + assert!(stdout.contains("John as the query")); + + Ok(()) +}