Skip to content

Commit 0f3cf7f

Browse files
committed
confirm dialog for canceling delete, refactor install confim dialog
1 parent 1bc08a2 commit 0f3cf7f

2 files changed

Lines changed: 92 additions & 37 deletions

File tree

rust/stackablectl/src/cmds/demo.rs

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -410,29 +410,32 @@ async fn install_cmd(
410410
// `stackablectl demo uninstall` relies on namespace deletion, suggest installing in a non-default namespace
411411
// It should still be possible to skip that if either uninstall is not needed
412412
// or installing an older version of the demo which only supports the 'default' namespace
413-
let demo_namespace = tracing_indicatif::suspend_tracing_indicatif(
414-
|| -> Result<String, CmdError> {
415-
if args.namespaces.namespace == DEFAULT_NAMESPACE {
416-
if Confirm::new()
413+
let demo_namespace;
414+
415+
if args.namespaces.namespace == DEFAULT_NAMESPACE {
416+
// Ask to install in a non-default namespace, currently suggesting the demo name as namespace name
417+
let use_non_default_namespace = tracing_indicatif::suspend_tracing_indicatif(
418+
|| -> Result<bool, CmdError> {
419+
Confirm::new()
417420
.with_prompt(
418421
format!(
419422
"Demos installed in the {DEFAULT_NAMESPACE:?} namespace cannot be uninstalled with stackablectl. Install the demo in the {demo_namespace:?} namespace instead?",
420423
demo_namespace = args.demo_name.clone())
421424
)
422425
.default(true)
423426
.interact()
424-
.context(ConfirmDialogSnafu)? {
425-
// User selected to install in suggested namespace
426-
Ok(args.demo_name.clone())
427-
} else {
428-
// User selected to install in default namespace
429-
Ok(args.namespaces.namespace.clone())
430-
}
431-
} else {
432-
Ok(args.namespaces.namespace.clone())
433-
}
434-
},
435-
)?;
427+
.context(ConfirmDialogSnafu)
428+
},
429+
)?;
430+
431+
if use_non_default_namespace {
432+
demo_namespace = args.demo_name.clone();
433+
} else {
434+
demo_namespace = args.namespaces.namespace.clone();
435+
}
436+
} else {
437+
demo_namespace = args.namespaces.namespace.clone();
438+
}
436439

437440
let values_file = cli.get_values_file().context(PathOrUrlParseSnafu)?;
438441
let operator_values = load_operator_values(values_file.as_ref(), transfer_client)
@@ -509,12 +512,36 @@ async fn uninstall_cmd(
509512
transfer_client: &xfer::Client,
510513
release_branch: &str,
511514
) -> Result<String, CmdError> {
512-
info!(demo_name = %args.demo_name, "Uninstalling demo");
513-
Span::current().pb_set_message(&format!("Uninstalling demo {}", args.demo_name));
514-
515515
// Init result output and progress output
516516
let mut output = Cli::result();
517517

518+
let proceed_with_uninstall = tracing_indicatif::suspend_tracing_indicatif(
519+
|| -> Result<bool, CmdError> {
520+
Confirm::new()
521+
.with_prompt(
522+
format!(
523+
"Uninstalling the demo {demo_name:?} will delete the {demo_namespace:?} namespace. This action cannot be undone. Proceed?",
524+
demo_name = args.demo_name.clone(),
525+
demo_namespace = args.namespaces.namespace.clone())
526+
)
527+
.default(true)
528+
.interact()
529+
.context(ConfirmDialogSnafu)
530+
},
531+
)?;
532+
533+
if !proceed_with_uninstall {
534+
output.with_output(format!(
535+
"Uninstalling demo {demo_name:?} canceled",
536+
demo_name = args.demo_name.clone()
537+
));
538+
539+
return Ok(output.render());
540+
}
541+
542+
info!(demo_name = %args.demo_name, "Uninstalling demo");
543+
Span::current().pb_set_message(&format!("Uninstalling demo {}", args.demo_name));
544+
518545
let demo = list.get(&args.demo_name).ok_or(CmdError::NoSuchDemo {
519546
name: args.demo_name.clone(),
520547
})?;

rust/stackablectl/src/cmds/stack.rs

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -388,29 +388,32 @@ async fn install_cmd(
388388
// `stackablectl stack uninstall` relies on namespace deletion, suggest installing in a non-default namespace
389389
// It should still be possible to skip that if either uninstall is not needed
390390
// or installing an older version of the stack which only supports the 'default' namespace
391-
let stack_namespace = tracing_indicatif::suspend_tracing_indicatif(
392-
|| -> Result<String, CmdError> {
393-
if args.namespaces.namespace == DEFAULT_NAMESPACE {
394-
if Confirm::new()
391+
let stack_namespace;
392+
393+
if args.namespaces.namespace == DEFAULT_NAMESPACE {
394+
// Ask to install in a non-default namespace, currently suggesting the stack name as namespace name
395+
let use_non_default_namespace = tracing_indicatif::suspend_tracing_indicatif(
396+
|| -> Result<bool, CmdError> {
397+
Confirm::new()
395398
.with_prompt(
396399
format!(
397-
"Stacks installed in the '{DEFAULT_NAMESPACE}' namespace cannot be uninstalled with stackablectl. Install the stack in the '{stack_namespace}' namespace instead?",
400+
"Stacks installed in the {DEFAULT_NAMESPACE:?} namespace cannot be uninstalled with stackablectl. Install the stack in the {stack_namespace:?} namespace instead?",
398401
stack_namespace = args.stack_name.clone())
399402
)
400403
.default(true)
401404
.interact()
402-
.context(ConfirmDialogSnafu)? {
403-
// User selected to install in suggested namespace
404-
Ok(args.stack_name.clone())
405-
} else {
406-
// User selected to install in default namespace
407-
Ok(args.namespaces.namespace.clone())
408-
}
409-
} else {
410-
Ok(args.namespaces.namespace.clone())
411-
}
412-
},
413-
)?;
405+
.context(ConfirmDialogSnafu)
406+
},
407+
)?;
408+
409+
if use_non_default_namespace {
410+
stack_namespace = args.stack_name.clone();
411+
} else {
412+
stack_namespace = args.namespaces.namespace.clone();
413+
}
414+
} else {
415+
stack_namespace = args.namespaces.namespace.clone();
416+
}
414417

415418
let values_file = cli.get_values_file().context(PathOrUrlParseSnafu)?;
416419
let operator_values = load_operator_values(values_file.as_ref(), transfer_client)
@@ -479,12 +482,37 @@ async fn uninstall_cmd(
479482
stack_list: stack::StackList,
480483
transfer_client: &xfer::Client,
481484
) -> Result<String, CmdError> {
485+
let mut output = Cli::result();
486+
487+
let proceed_with_uninstall = tracing_indicatif::suspend_tracing_indicatif(
488+
|| -> Result<bool, CmdError> {
489+
Confirm::new()
490+
.with_prompt(
491+
format!(
492+
"Uninstalling the stack {stack_name:?} will delete the {stack_namespace:?} namespace. This action cannot be undone. Proceed?",
493+
stack_name = args.stack_name.clone(),
494+
stack_namespace = args.namespaces.namespace.clone())
495+
)
496+
.default(true)
497+
.interact()
498+
.context(ConfirmDialogSnafu)
499+
},
500+
)?;
501+
502+
if !proceed_with_uninstall {
503+
output.with_output(format!(
504+
"Uninstalling stack {stack_name:?} canceled",
505+
stack_name = args.stack_name.clone()
506+
));
507+
508+
return Ok(output.render());
509+
}
510+
482511
info!(stack_name = %args.stack_name, "Uninstalling stack");
483512
Span::current().pb_set_message(&format!("Uninstalling stack {}", args.stack_name));
484513

485514
match stack_list.get(&args.stack_name) {
486515
Some(stack) => {
487-
let mut output = Cli::result();
488516
let client = Client::new().await.context(KubeClientCreateSnafu)?;
489517

490518
let files = cli.get_release_files().context(PathOrUrlParseSnafu)?;

0 commit comments

Comments
 (0)