From 209547fd7bdca33f26c783de9da2aa6d1ef5084b Mon Sep 17 00:00:00 2001 From: sycured <60801403+sycured@users.noreply.github.com> Date: Sun, 13 Aug 2023 00:50:35 -0500 Subject: [PATCH] project: add flag to disable undo on delete --- src/cli/project/cli_commands.rs | 9 ++++++++- src/cli/project/cli_logic.rs | 1 + src/library/project.rs | 7 +++++-- test_project_destroy.exp | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cli/project/cli_commands.rs b/src/cli/project/cli_commands.rs index 2d75c87..fd1811c 100644 --- a/src/cli/project/cli_commands.rs +++ b/src/cli/project/cli_commands.rs @@ -5,7 +5,7 @@ * SPDX-License-Identifier: GPL-2.0-only */ -use clap::{Arg, Command}; +use clap::{Arg, ArgAction::SetTrue, Command}; pub fn create() -> Command { Command::new("create") @@ -46,6 +46,13 @@ pub fn delete_project() -> Command { .visible_aliases(["destroy", "destroy_project"]) .about("Delete project") .arg_required_else_help(true) + .arg(Arg::new("disable_undo") + .long("disable_undo") + .short('d') + .help("Activate the direct deletion so the project isn't placed in the Jira recycle bin avoiding restauration.") + .required(false) + .action(SetTrue) + ) .arg(Arg::new("project_key").help("Project key").required(true)) } diff --git a/src/cli/project/cli_logic.rs b/src/cli/project/cli_logic.rs index 9d18346..97d9817 100644 --- a/src/cli/project/cli_logic.rs +++ b/src/cli/project/cli_logic.rs @@ -27,6 +27,7 @@ pub fn delete_project(global: &Global, args: &ArgMatches) { project::delete( global, args.get_one::("project_key").unwrap().as_str(), + !args.get_flag("disable_undo"), ); } diff --git a/src/library/project.rs b/src/library/project.rs index 668f8a8..0db5838 100644 --- a/src/library/project.rs +++ b/src/library/project.rs @@ -45,8 +45,11 @@ pub fn create( } #[allow(clippy::unit_arg)] -pub fn delete(global: &Global, project_key: &str) { - let url: String = format!("https://{}{}/{project_key}", global.domain, URLS["project"]); +pub fn delete(global: &Global, project_key: &str, enable_undo: bool) { + let url: String = format!( + "https://{}{}/{project_key}?enableUndo={enable_undo}", + global.domain, URLS["project"] + ); if confirm(format!( "Are you sure you want to delete the project key: {project_key}?" )) { diff --git a/test_project_destroy.exp b/test_project_destroy.exp index 6383c62..f7468fa 100755 --- a/test_project_destroy.exp +++ b/test_project_destroy.exp @@ -18,7 +18,7 @@ if {$force_conservative} { } set timeout -1 -spawn $env(JIRA_CLI) project delete_project $env(JIRA_PROJECT_KEY) +spawn $env(JIRA_CLI) project delete_project --disable_undo $env(JIRA_PROJECT_KEY) match_max 100000 expect -exact "Are you sure you want to delete the project key: $env(JIRA_PROJECT_KEY)? \[y/n\] \[?25l" send -- "y"