Skip to content

Commit

Permalink
project: add flag to disable undo on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
sycured committed Aug 13, 2023
1 parent 5678857 commit 209547f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/cli/project/cli_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))
}

Expand Down
1 change: 1 addition & 0 deletions src/cli/project/cli_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn delete_project(global: &Global, args: &ArgMatches) {
project::delete(
global,
args.get_one::<String>("project_key").unwrap().as_str(),
!args.get_flag("disable_undo"),
);
}

Expand Down
7 changes: 5 additions & 2 deletions src/library/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}?"
)) {
Expand Down
2 changes: 1 addition & 1 deletion test_project_destroy.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 209547f

Please sign in to comment.