Skip to content

Commit 18e7f70

Browse files
committed
refactor namespace confirmation
1 parent a6e2feb commit 18e7f70

2 files changed

Lines changed: 31 additions & 28 deletions

File tree

rust/stackablectl/src/cmds/demo.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -410,30 +410,31 @@ 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;
413+
let non_default_namespace_confirmation = || -> Result<bool, CmdError> {
414+
// Ask to install in a non-default namespace, currently suggesting the demo name as namespace name
415+
Confirm::new()
416+
.with_prompt(
417+
format!(
418+
"Demos installed in the {DEFAULT_NAMESPACE:?} namespace cannot be uninstalled with stackablectl. Install the demo in the {demo_namespace:?} namespace instead?",
419+
demo_namespace = args.demo_name.clone())
420+
)
421+
.default(true)
422+
.interact()
423+
.context(ConfirmDialogSnafu)
424+
};
414425

426+
let demo_namespace;
415427
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()
420-
.with_prompt(
421-
format!(
422-
"Demos installed in the {DEFAULT_NAMESPACE:?} namespace cannot be uninstalled with stackablectl. Install the demo in the {demo_namespace:?} namespace instead?",
423-
demo_namespace = args.demo_name.clone())
424-
)
425-
.default(true)
426-
.interact()
427-
.context(ConfirmDialogSnafu)
428-
},
429-
)?;
428+
let use_non_default_namespace =
429+
tracing_indicatif::suspend_tracing_indicatif(non_default_namespace_confirmation)?;
430430

431431
if use_non_default_namespace {
432432
demo_namespace = args.demo_name.clone();
433433
} else {
434434
demo_namespace = args.namespaces.namespace.clone();
435435
}
436436
} else {
437+
// User provided a non-default namespace with command argument
437438
demo_namespace = args.namespaces.namespace.clone();
438439
}
439440

rust/stackablectl/src/cmds/stack.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -388,22 +388,23 @@ 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;
391+
let non_default_namespace_confirmation = || -> Result<bool, CmdError> {
392+
// Ask to install in a non-default namespace, currently suggesting the stack name as namespace name
393+
Confirm::new()
394+
.with_prompt(
395+
format!(
396+
"Stacks installed in the {DEFAULT_NAMESPACE:?} namespace cannot be uninstalled with stackablectl. Install the stack in the {stack_namespace:?} namespace instead?",
397+
stack_namespace = args.stack_name.clone())
398+
)
399+
.default(true)
400+
.interact()
401+
.context(ConfirmDialogSnafu)
402+
};
392403

404+
let stack_namespace;
393405
if args.namespaces.namespace == DEFAULT_NAMESPACE {
394-
// Ask to install in a non-default namespace, currently suggesting the stack name as namespace name
395406
let use_non_default_namespace = tracing_indicatif::suspend_tracing_indicatif(
396-
|| -> Result<bool, CmdError> {
397-
Confirm::new()
398-
.with_prompt(
399-
format!(
400-
"Stacks installed in the {DEFAULT_NAMESPACE:?} namespace cannot be uninstalled with stackablectl. Install the stack in the {stack_namespace:?} namespace instead?",
401-
stack_namespace = args.stack_name.clone())
402-
)
403-
.default(true)
404-
.interact()
405-
.context(ConfirmDialogSnafu)
406-
},
407+
non_default_namespace_confirmation,
407408
)?;
408409

409410
if use_non_default_namespace {
@@ -412,6 +413,7 @@ async fn install_cmd(
412413
stack_namespace = args.namespaces.namespace.clone();
413414
}
414415
} else {
416+
// User provided a non-default namespace with command argument
415417
stack_namespace = args.namespaces.namespace.clone();
416418
}
417419

0 commit comments

Comments
 (0)