|
8 | 8 | styler.ignore_start = "# styler: off", |
9 | 9 | styler.ignore_stop = "# styler: on", |
10 | 10 | styler.quiet = FALSE, |
11 | | - styler.test_dir_writable = TRUE |
| 11 | + styler.test_dir_writable = TRUE, |
| 12 | + styler.interactive_ask_remove_old_caches = TRUE |
12 | 13 | ) |
13 | 14 | toset <- !(names(op.styler) %in% names(op)) |
14 | 15 | if (any(toset)) options(op.styler[toset]) |
| 16 | + remind_removing_old_cache() |
15 | 17 | invisible() |
16 | 18 | } |
| 19 | + |
| 20 | +#' Ask people to remove the cache |
| 21 | +#' |
| 22 | +#' The way RStudio Startup works does not allow o read the prompt for some |
| 23 | +#' reasons (https://stackoverflow.com/questions/55772436/readline-does-not-prompt-user-input-from-rprofile-site-in-rstudio) |
| 24 | +#' So we better don't use the prompt and issue a message only. |
| 25 | +#' @keywords internal |
| 26 | +remind_removing_old_cache <- function() { |
| 27 | + if (interactive() && getOption("styler.interactive_ask_remove_old_caches", TRUE)) { |
| 28 | + dirs <- list.dirs(R.cache::getCachePath("styler"), recursive = FALSE) |
| 29 | + dirs <- dirs[unname(sapply(dirs, function(x) length(list.files(x)) > 0))] |
| 30 | + package_versions <- package_version(basename(dirs), strict = FALSE) |
| 31 | + package_versions <- package_versions[!is.na(package_versions)] |
| 32 | + old_package_versions <- package_versions[package_versions < styler_version] |
| 33 | + if (length(old_package_versions) < 1) { |
| 34 | + return() |
| 35 | + } |
| 36 | + |
| 37 | + cmd <- glue::glue("styler::cache_clear(\"{basename(dirs)}\", ask = FALSE)") %>% |
| 38 | + paste0(collapse = "\n") |
| 39 | + cli::cli_alert_info(paste0( |
| 40 | + "You are using {{styler}} version {styler_version} but we found ", |
| 41 | + "caches for older versions of {{styler}}.\n", |
| 42 | + "You can delete them with the following commands:" |
| 43 | + )) |
| 44 | + cat("\n") |
| 45 | + cli::cli_code(cmd) |
| 46 | + cat("\n") |
| 47 | + cli::cli_alert_info( |
| 48 | + paste( |
| 49 | + "We'll remind you every time you update {{styler}}.", |
| 50 | + "To suppress this prompt in the future:" |
| 51 | + ) |
| 52 | + ) |
| 53 | + cat("\n") |
| 54 | + cli::cli_code( |
| 55 | + 'options("styler.interactive_ask_remove_old_caches" = FALSE)' |
| 56 | + ) |
| 57 | + } |
| 58 | +} |
0 commit comments