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: add --no-prompt #112

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions src/commands/global_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 15 additions & 7 deletions src/commands/lab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ async fn handle_vscode_integration(
async fn ask_for_install_vscode_extensions(
allow_vscode_extensions: Option<bool>,
pb: &ProgressBar,
no_prompt: bool,
) -> Result<()> {
let mut vscode_settings = UserVSCodeSettings::load().await?;

Expand Down Expand Up @@ -148,20 +149,22 @@ 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)
.default(true)
.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)
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion src/commands/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
pub async fn check_login(
global: GlobalArgs,
multi_progress: &MultiProgress,
no_prompt: bool,
) -> Result<bool> {
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(
Expand Down
15 changes: 11 additions & 4 deletions src/commands/template.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
colors::ColorChoiceExt,
commands::{
clean::{clean, Clean},
install::{install, Install},
login::check_login,
GlobalArgs,
Expand Down Expand Up @@ -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?;

Expand Down Expand Up @@ -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::<GetViewerEnabledEntities>(get_viewer_enabled_entities::Variables {
resource: competition.id,
Expand Down Expand Up @@ -222,15 +223,21 @@ 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
};
install(
Install {
competition: Some(args.competition),
..Default::default()
upgrade: true,
},
install_global,
)
Expand Down
25 changes: 23 additions & 2 deletions src/commands/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,17 @@ async fn update_project_version(
last_version: Option<&Version>,
pb: &ProgressBar,
color: ColorChoice,
no_prompt: bool,
) -> Result<Version> {
let mut version = project.version().unwrap();

if let Some(last_version) = last_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}.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -491,6 +495,7 @@ pub async fn upload_use_case(
competition.version.as_ref(),
&use_case_pb,
global.color,
global.no_prompt,
)
.await?;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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?;

Expand Down
Loading