Skip to content

Commit 2c847b4

Browse files
committed
add check removal approval func
1 parent 7e42470 commit 2c847b4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

R/utils-prompt.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ check_extension_approval <- function(no_prompt = FALSE, what = "Something", see_
2323
}
2424
}
2525

26+
check_removal_approval <- function(no_prompt = FALSE, what = "Something", see_more_at = NULL) {
27+
if (no_prompt) return(TRUE)
28+
29+
if (!is_interactive()) {
30+
cli::cli_abort(c(
31+
"{ what } requires explicit approval.",
32+
">" = "Set {.arg no_prompt = TRUE} if you agree.",
33+
if (!is.null(see_more_at)) {
34+
c(i = "See more at {.url {see_more_at}}")
35+
}
36+
))
37+
} else {
38+
prompt_value <- tolower(readline(sprintf("? Are you sure you'd like to remove %s (Y/n)? ", what)))
39+
if (!prompt_value %in% "y") {
40+
return(invisible(FALSE))
41+
}
42+
return(invisible(TRUE))
43+
}
44+
}
45+
2646
# Add binding to base R function for testthat mocking
2747
readline <- NULL
2848
# Add binding to function from other package for mocking later on

0 commit comments

Comments
 (0)