diff --git a/src/commands/global_args.rs b/src/commands/global_args.rs index 99b9c9e..ab94c0f 100644 --- a/src/commands/global_args.rs +++ b/src/commands/global_args.rs @@ -44,6 +44,9 @@ pub struct GlobalArgs { pub color: ColorChoice, #[arg(value_enum, long, default_value_t = LinkMode::Copy, global = true)] pub dep_link_mode: LinkMode, + /// Do not prompt + #[arg(short = 'y', long, global = true)] + pub no_prompt: bool, } impl GlobalArgs { diff --git a/src/commands/lab.rs b/src/commands/lab.rs index 87dd1ac..1eea7c5 100644 --- a/src/commands/lab.rs +++ b/src/commands/lab.rs @@ -116,6 +116,7 @@ async fn handle_vscode_integration( async fn ask_for_install_vscode_extensions( allow_vscode_extensions: Option, pb: &ProgressBar, + no_prompt: bool, ) -> Result<()> { let mut vscode_settings = UserVSCodeSettings::load().await?; @@ -148,9 +149,11 @@ async fn ask_for_install_vscode_extensions( format_extensions() ); - let can_install = tokio::task::spawn_blocking({ + let can_install = if no_prompt { + false + } else { let pb = pb.clone(); - move || { + tokio::task::spawn_blocking(move || { pb.suspend(|| { Confirm::new() .with_prompt(prompt_message) @@ -158,10 +161,10 @@ async fn ask_for_install_vscode_extensions( .interact() .map_err(|_| error::system("Failed to read input", "Please try again")) }) - } - }) - .await - .map_err(|_| error::user("The extension installation prompt was interrupted.", ""))??; + }) + .await + .map_err(|_| error::user("The extension installation prompt was interrupted.", ""))?? + }; vscode_settings .can_install_extensions(can_install) @@ -199,7 +202,12 @@ pub async fn lab(args: Lab, global_args: GlobalArgs) -> Result<()> { .can_install_extensions .is_none() { - ask_for_install_vscode_extensions(args.allow_vscode_extensions, &pb).await?; + ask_for_install_vscode_extensions( + args.allow_vscode_extensions, + &pb, + global_args.no_prompt, + ) + .await?; } handle_vscode_integration(global_args, &env, &pb).await } else { diff --git a/src/commands/login.rs b/src/commands/login.rs index 850e2b8..0e34966 100644 --- a/src/commands/login.rs +++ b/src/commands/login.rs @@ -386,10 +386,17 @@ pub async fn login(args: Login, global: GlobalArgs) -> Result<()> { do_login(args, global, default_spinner()).await } -pub async fn check_login(global: GlobalArgs, multi_progress: &MultiProgress) -> Result { +pub async fn check_login( + global: GlobalArgs, + multi_progress: &MultiProgress, + no_prompt: bool, +) -> Result { if get_credentials(global.aqora_url()?).await?.is_some() { return Ok(true); } + if no_prompt { + return Ok(false); + } let confirmation = multi_progress.suspend(|| { dialoguer::Confirm::with_theme(global.color.dialoguer().as_ref()) .with_prompt( diff --git a/src/commands/template.rs b/src/commands/template.rs index e1e7c79..1fb427e 100644 --- a/src/commands/template.rs +++ b/src/commands/template.rs @@ -1,6 +1,7 @@ use crate::{ colors::ColorChoiceExt, commands::{ + clean::{clean, Clean}, install::{install, Install}, login::check_login, GlobalArgs, @@ -46,7 +47,7 @@ pub struct Template { pub async fn template(args: Template, global: GlobalArgs) -> Result<()> { let m = MultiProgress::new(); - let logged_in = check_login(global.clone(), &m).await?; + let logged_in = check_login(global.clone(), &m, global.no_prompt).await?; let client = GraphQLClient::new(global.url.parse()?).await?; @@ -110,7 +111,7 @@ pub async fn template(args: Template, global: GlobalArgs) -> Result<()> { })? .download_url; - let organization = if logged_in { + let organization = if logged_in && !global.no_prompt { let viewer = client .send::(get_viewer_enabled_entities::Variables { resource: competition.id, @@ -222,7 +223,13 @@ pub async fn template(args: Template, global: GlobalArgs) -> Result<()> { })?; } - if !args.no_install { + if args.no_install { + let clean_global = GlobalArgs { + project: destination.clone(), + ..global + }; + clean(Clean, clean_global).await?; + } else { let install_global = GlobalArgs { project: destination.clone(), ..global @@ -230,7 +237,7 @@ pub async fn template(args: Template, global: GlobalArgs) -> Result<()> { install( Install { competition: Some(args.competition), - ..Default::default() + upgrade: true, }, install_global, ) diff --git a/src/commands/upload.rs b/src/commands/upload.rs index f6bea0c..a647866 100644 --- a/src/commands/upload.rs +++ b/src/commands/upload.rs @@ -388,6 +388,7 @@ async fn update_project_version( last_version: Option<&Version>, pb: &ProgressBar, color: ColorChoice, + no_prompt: bool, ) -> Result { let mut version = project.version().unwrap(); @@ -395,6 +396,9 @@ async fn update_project_version( if last_version >= &version { let new_version = increment_version(last_version); let confirmation = pb.suspend(|| { + if no_prompt { + return Ok(false); + } dialoguer::Confirm::with_theme(color.dialoguer().as_ref()) .with_prompt(format!( r#"Project version must be greater than {last_version}. @@ -426,7 +430,7 @@ pub async fn upload_use_case( mut project: PyProject, ) -> Result<()> { let m = MultiProgress::new(); - check_login(global.clone(), &m).await?; + check_login(global.clone(), &m, global.no_prompt).await?; project.validate_version().map_err(|err| { error::user( @@ -491,6 +495,7 @@ pub async fn upload_use_case( competition.version.as_ref(), &use_case_pb, global.color, + global.no_prompt, ) .await?; @@ -711,7 +716,7 @@ pub async fn upload_submission( mut project: PyProject, ) -> Result<()> { let m = MultiProgress::new(); - check_login(global.clone(), &m).await?; + check_login(global.clone(), &m, global.no_prompt).await?; let use_case_toml_path = project_use_case_toml_path(&global.project); if !use_case_toml_path.exists() { @@ -819,6 +824,9 @@ pub async fn upload_submission( } let accepts = m.suspend(|| { + if global.no_prompt { + return false; + } let will_review = dialoguer::Confirm::with_theme(global.color.dialoguer().as_ref()) .with_prompt(format!("{message} Would you like to review them now?")) .default(true) @@ -873,6 +881,9 @@ pub async fn upload_submission( let evaluation_path = project_last_run_dir(&global.project); if !evaluation_path.exists() { let confirmation = m.suspend(|| { + if global.no_prompt { + return Ok(false); + } dialoguer::Confirm::with_theme(global.color.dialoguer().as_ref()) .with_prompt( r#"No last run result found. @@ -905,6 +916,9 @@ Would you like to run the tests now?"#, if let Ok(last_run_result) = last_run_result.as_ref() { if last_run_result.use_case_version.as_ref() != Some(&use_case_version) { let confirmation = m.suspend(|| { + if global.no_prompt { + return Ok(false); + } dialoguer::Confirm::with_theme(global.color.dialoguer().as_ref()) .with_prompt( r#"It seems the use case version has changed since the last test run. @@ -942,6 +956,9 @@ Do you want to run the tests now?"#, } if should_run_tests { let confirmation = m.suspend(|| { + if global.no_prompt { + return Ok(false); + } dialoguer::Confirm::with_theme(global.color.dialoguer().as_ref()) .with_prompt( r#"It seems you have made some changes since since the last test run. @@ -958,6 +975,9 @@ Do you want to re-run the tests now?"#, } } else { let confirmation = m.suspend(|| { + if global.no_prompt { + return Ok(false); + } dialoguer::Confirm::with_theme(global.color.dialoguer().as_ref()) .with_prompt( r#"It seems the last test run result is corrupted or missing. @@ -983,6 +1003,7 @@ Do you want to run the tests now?"#, submission_version.as_ref(), &use_case_pb, global.color, + global.no_prompt, ) .await?;