diff --git a/R/utils.R b/R/utils.R index 02a2a4e..54bb09d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -10,24 +10,51 @@ #' #' @export use_box_lsp <- function(file_path = ".Rprofile") { - response <- readline( - glue::glue("Would you like to create or modify the `{file_path}` file? (yes/No) ") - ) - response <- substr(response, 1, 1) - if (!(response == "Y" || response == "y")) { - cli::cli_abort("`{file_path}` file creation/modification cancelled!") - } - rprofile <- fs::path_package("box.lsp", "Rprofile.R") to_write <- readLines(rprofile) tryCatch({ if (file.exists(file_path)) { + response <- readline( + cli::cli( + cli::cli_alert( + c( + "`{file_path}` exists. Lines will be added to the end of this file. ", + "Would you like to continue (yes/No)" + ), + wrap = TRUE + ) + ) + ) + response <- substr(response, 1, 1) + if (!(response == "Y" || response == "y")) { + cli::cli_inform("`{file_path}` file append cancelled.") + return(invisible(NULL)) + } + cli::cli_alert_info( - "{file_path} exists. Will append {{box.lsp}} configuration lines to the file." + "Appending {{box.lsp}} configuration lines to the `{file_path}`." ) write("", file = file_path, append = TRUE) + } else { + response <- readline( + cli::cli( + cli::cli_alert( + "Would you like to create `{file_path}` with {{box_lsp}} configuration? (yes/No)", + wrap = TRUE) + ) + ) + response <- substr(response, 1, 1) + if (!(response == "Y" || response == "y")) { + cli::cli_inform("`{file_path}` file creation cancelled.") + return(invisible(NULL)) + } + + cli::cli_alert_info( + "Creating `{file_path}` with {{box.lsp}} configuration." + ) } + write(to_write, file = file_path, append = TRUE) cli::cli_alert_success( c(