Skip to content

Commit

Permalink
feat: handle newer version - fix #31
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Feb 8, 2024
1 parent dd59719 commit 9685bc0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
44 changes: 41 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,17 @@ set_zen_version <- function(version) {

check_zen_version(version)

versions <- zen_list_versions()
versions <- zen_list_versions()
latest_version <- get_zen_latest_version()

if (is.null(version)) {

version <- versions[which.max(as.Date(versions$"publication_date")),
"version"]
version <- get_in_use_version()

if (is.null(version)) {

version <- latest_version
}

} else {

Expand All @@ -215,5 +220,38 @@ set_zen_version <- function(version) {
}
}

if (version != latest_version) {

answer <- readline(paste0("A newer version of the FORCIS database is ",
"available. Do you want to download it [Y/n]? "))

if (answer == "") answer <- "y"

answer <- tolower(answer)

if (!(answer %in% c("y", "n"))) {
stop("Please type 'y' or 'n'", call. = FALSE)
}

if (answer == "y") {
version <- latest_version
}
}

set_in_use_version(version)

version
}



#' Get Zenodo latest version
#'
#' @noRd

get_zen_latest_version <- function() {

versions <- zen_list_versions()

versions[which.max(as.Date(versions$"publication_date")), "version"]
}
4 changes: 1 addition & 3 deletions R/versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ get_in_use_version <- function() {
#'
#' @noRd

set_in_use_version <- function(version = NULL) {

version <- set_zen_version(version)
set_in_use_version <- function(version) {

saved_version <- get_in_use_version()

Expand Down

0 comments on commit 9685bc0

Please sign in to comment.