Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cli functions #2378

Merged
merged 20 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions R/build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ build_articles <- function(pkg = ".",
return(invisible())
}

rule("Building articles")
cli::cli_h2("Building articles")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved

build_articles_index(pkg)
purrr::walk(
Expand Down Expand Up @@ -207,7 +207,7 @@ build_article <- function(name,
# allow code sharing with building of the index.
vig <- match(name, pkg$vignettes$name)
if (is.na(vig)) {
stop("Can't find article called ", src_path(name), call. = FALSE)
cli::cli_abort("Can't find article {ui_path(name)}")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
}

input <- pkg$vignettes$file_in[vig]
Expand Down Expand Up @@ -368,12 +368,8 @@ data_articles_index <- function(pkg = ".") {
missing <- setdiff(pkg$vignettes$name, c(listed, pkg$package))

if (length(missing) > 0) {
abort(
paste0(
"Vignettes missing from index: ",
paste(missing, collapse = ", ")
),
call. = FALSE
cli::cli_abort(
"Vignette{?s} missing from index: {missing}"
)
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -385,7 +381,9 @@ data_articles_index <- function(pkg = ".") {

data_articles_index_section <- function(section, pkg) {
if (!set_contains(names(section), c("title", "contents"))) {
abort("Section must have components `title`, `contents`")
cli::cli_abort(
"Section must have components {.field title, contents}"
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
)
}

# Match topics against any aliases
Expand Down Expand Up @@ -424,7 +422,6 @@ default_articles_index <- function(pkg = ".") {
return(NULL)
}


print_yaml(list(
list(
title = tr_("All vignettes"),
Expand Down
34 changes: 19 additions & 15 deletions R/build-favicons.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
rlang::check_installed("openssl")
pkg <- as_pkgdown(pkg)

rule("Building favicons")
cli::cli_rule("Building favicons")

logo_path <- find_logo(pkg$src_path)

if (is.null(logo_path)) {
stop("Can't find package logo PNG or SVG to build favicons.", call. = FALSE)
cli::cli_abort("Can't find package logo PNG or SVG to build favicons.")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
}

if (has_favicons(pkg) && !overwrite) {
message("Favicons already exist in `pkgdown/`. Set `overwrite = TRUE` to re-create.")
cli::cli_inform(c(
"Favicons already exist in {.path pkgdown}",
"i" = "Set {.var overwrite = TRUE} to re-create."
))
return(invisible())
}

message("Building favicons with realfavicongenerator.net...")
cli::cli_inform("Building favicons with {.url https://realfavicongenerator.net} ...")

logo <- readBin(logo_path, what = "raw", n = fs::file_info(logo_path)$size)

Expand Down Expand Up @@ -66,17 +69,18 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
quiet = TRUE
)
if (httr::http_error(resp)) {
stop("API request failed.", call. = FALSE)
cli::cli_abort("API request failed.")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
}

content <- httr::content(resp)
result <- content$favicon_generation_result

if (!identical(result$result$status, "success")) {
stop(
"API request failed. ", "
Please submit bug report to <https://github.com/r-lib/pkgdown/issues>",
call. = FALSE
cli::cli_abort(
c(
"API request failed.",
"i" = "{.href [Please submit a bug report](https://github.com/r-lib/pkgdown/issues)}"
)
)
}

Expand All @@ -93,10 +97,10 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
utils::unzip(tmp, exdir = path(pkg$src_path, "pkgdown", "favicon"))
},
warning = function(e) {
abort("Your logo file couldn't be processed and may be corrupt.", parent = e)
cli::cli_abort("Your logo file couldn't be processed and may be corrupt.")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
},
error = function(e) {
abort("Your logo file couldn't be processed and may be corrupt.", parent = e)
cli::cli_abort("Your logo file couldn't be processed and may be corrupt.")
})

invisible()
Expand All @@ -107,10 +111,10 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
#' @inheritParams build_favicons
#' @export
build_favicon <- function(pkg, overwrite) {
message(
"`build_favicon()` is deprecated as of pkgdown 1.4.0. ",
"Please use `build_favicons()` instead."
)
cli::cli_warn(c(
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
"{.fun build_favicon} is deprecated as of pkgdown 1.4.0. ",
"i" = "Please use {.fun build_favicons} instead."
))
build_favicons(pkg, overwrite)
}

Expand Down
4 changes: 2 additions & 2 deletions R/build-github.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build_site_github_pages <- function(pkg = ".",
pkg <- as_pkgdown(pkg, override = list(destination = dest_dir))

if (clean) {
rule("Cleaning files from old site", line = 1)
cli::cli_rule("Cleaning files from old site")
clean_site(pkg)
}

Expand All @@ -36,7 +36,7 @@ build_site_github_pages <- function(pkg = ".",
}

build_github_pages <- function(pkg = ".") {
rule("Extra files for GitHub pages")
cli::cli_rule("Extra files for GitHub pages")
pkg <- as_pkgdown(pkg)

# Add .nojekyll since site is static HTML
Expand Down
2 changes: 1 addition & 1 deletion R/build-home-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ role_lookup <- function(abbr) {
out <- unname(roles[abbr])
if (any(is.na(out))) {
missing <- paste0("'", abbr[is.na(out)], "'", collapse = ", ")
warn(paste0("Unknown MARC role abbreviation ", missing))
cli::cli_alert_warning("Unknown MARC role abbreviation{?s}: {missing}")
out[is.na(out)] <- abbr[is.na(out)]
}
out
Expand Down
16 changes: 6 additions & 10 deletions R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ data_home_sidebar <- function(pkg = ".") {

if (length(html_path)) {
if (!file.exists(html_path)) {
abort(
sprintf(
"Can't find file '%s' specified by %s.",
pkg$meta$home$sidebar$html,
pkgdown_field(pkg, c("home", "sidebar", "html"))
)
cli::cli_abort(
"Can't find file {.file {html_path}} specified by {pkgdown_field(pkg, c('home', 'sidebar', 'html'))}"
)
}
return(read_file(html_path))
Expand Down Expand Up @@ -215,10 +211,10 @@ check_missing_images <- function(pkg, src_path, dst_path) {
exists <- fs::file_exists(path(pkg$dst_path, rel_path))

if (any(!exists)) {
paths <- encodeString(rel_src[!exists], quote = "'")
warn(c(
paste0("Missing images in '", src_path, "': ", paste0(paths, collapse = ", ")),
i = "pkgdown can only use images in 'man/figures' and 'vignettes'"
paths <- rel_src[!exists]
cli::cli_warn(c(
"Missing images in {.file {src_path}}: {.file {paths}}",
"i" = "pkgdown can only use images in {.file man/figures} and {.file vignettes}"
))
}
}
2 changes: 1 addition & 1 deletion R/build-home-md.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build_home_md <- function(pkg) {
}

render_md <- function(pkg, filename) {
cat_line("Reading ", src_path(path_rel(filename, pkg$src_path)))
cli::cli_alert_info("Reading {src_path(path_rel(filename, pkg$src_path))}")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved

body <- markdown_body(filename, strip_header = TRUE)
path <- path_ext_set(basename(filename), "html")
Expand Down
2 changes: 1 addition & 1 deletion R/build-home.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ build_home <- function(pkg = ".",
quiet = TRUE) {

pkg <- section_init(pkg, depth = 0L, override = override)
rule("Building home")
cli::cli_h2("Building home")
dir_create(pkg$dst_path)

build_citation_authors(pkg)
Expand Down
10 changes: 5 additions & 5 deletions R/build-news.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ build_news <- function(pkg = ".",
if (!has_news(pkg$src_path))
return()

rule("Building news")
cli::cli_h2("Building news")
dir_create(path(pkg$dst_path, "news"))

switch(news_style(pkg$meta),
Expand Down Expand Up @@ -151,7 +151,7 @@ data_news <- function(pkg = list()) {
sections <- xml2::xml_find_all(xml, "./body/div")
footnotes <- has_class(sections, "footnotes")
if (any(footnotes)) {
warn("Footnotes in NEWS.md are not currently supported")
cli::cli_warn("Footnotes in NEWS.md are not currently supported")
}
sections <- sections[!footnotes]

Expand All @@ -160,10 +160,10 @@ data_news <- function(pkg = list()) {
xml2::xml_name()
ulevels <- unique(levels)
if (!identical(ulevels, "h1") && !identical(ulevels, "h2")) {
abort(c(
cli::cli_abort(c(
"Invalid NEWS.md: inconsistent use of section headings.",
i = "Top-level headings must be either all <h1> or all <h2>.",
i = "See ?build_news for more details."
"i" = "Top-level headings must be either all <h1> or all <h2>.",
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
"i" = "See {.help pkgdown::build_news} for more details."
))
}
if (ulevels == "h1") {
Expand Down
6 changes: 3 additions & 3 deletions R/build-redirects.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ build_redirects <- function(pkg = ".",
return(invisible())
}

rule("Building redirects")
cli::cli_h2("Building redirects")
if (is.null(pkg$meta$url)) {
abort(sprintf("%s required to generate redirects", pkgdown_field(pkg, "url")))
cli::cli_abort(sprintf("%s required to generate redirects", pkgdown_field(pkg, "url")))
}

purrr::iwalk(
Expand All @@ -25,7 +25,7 @@ build_redirects <- function(pkg = ".",

build_redirect <- function(entry, index, pkg) {
if (!is.character(entry) || length(entry) != 2) {
abort(
cli::cli_abort(
sprintf(
"Entry %s in %s must be a character vector of length 2.",
index,
Expand Down
6 changes: 3 additions & 3 deletions R/build-reference.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ build_reference <- function(pkg = ".",
pkg <- section_init(pkg, depth = 1L, override = override)

if (!missing(document)) {
warning("`document` is deprecated. Please use `devel` instead.", call. = FALSE)
cli::cli_warn("{.var document}is deprecated. Please use {.var devel} instead.")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
devel <- document
}

rule("Building function reference")
cli::cli_h2("Building function reference")
build_reference_index(pkg)

copy_figures(pkg)
Expand Down Expand Up @@ -274,7 +274,7 @@ build_reference_topic <- function(topic,
if (lazy && !out_of_date(in_path, out_path))
return(invisible())

cat_line("Reading ", src_path("man", topic$file_in))
cli::cli_alert_info("Reading {src_path(path('man', topic$file_in))}")

data <- withCallingHandlers(
data_reference_topic(
Expand Down
4 changes: 2 additions & 2 deletions R/build-search-docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ build_sitemap <- function(pkg = ".") {
}

xml_path <- path(pkg$dst_path, "sitemap.xml")
cat_line("Writing ", dst_path(path_rel(xml_path, pkg$dst_path)))
cli::cli_alert_info("Writing {dst_path(path_rel(xml_path, pkg$dst_path))}")

xml2::write_xml(doc, file = xml_path)

Expand Down Expand Up @@ -86,7 +86,7 @@ url_node <- function(url) {
build_search <- function(pkg = ".",
override = list()) {
pkg <- section_init(pkg, depth = 1L, override = override)
rule("Building search index")
cli::cli_alert("Building search index")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
search_index <- build_search_index(pkg)
jsonlite::write_json(
search_index,
Expand Down
2 changes: 1 addition & 1 deletion R/build-tutorials.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ build_tutorials <- function(pkg = ".", override = list(), preview = NA) {
return(invisible())
}

rule("Building tutorials")
cli::cli_h2("Building tutorials")
dir_create(path(pkg$dst_path, "tutorials"))

data <- purrr::transpose(tutorials)
Expand Down
13 changes: 7 additions & 6 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,13 @@ build_site <- function(pkg = ".",
pkg <- as_pkgdown(pkg, override = override)

if (!missing(document)) {
warning("`document` is deprecated. Please use `devel` instead.", call. = FALSE)
cli::cli_warn("{.var document} is deprecated. Please use {.var devel} instead.")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
devel <- document
}

if (install) {
withr::local_temp_libpaths()
rule("Installing package into temporary library")
cli::cli_h2("Installing package {.pkg {pkg$package}} into temporary library")
# Keep source, so that e.g. pillar can show the source code
# of its functions in its articles
withr::with_options(
Expand Down Expand Up @@ -404,6 +404,7 @@ build_site_external <- function(pkg = ".",
timeout = getOption('pkgdown.timeout', Inf)
)

cli::cli_alert_success("finished building pkgdown site for {.pkg {pkg$package}}.")
preview_site(pkg, preview = preview)
invisible()
}
Expand All @@ -420,9 +421,9 @@ build_site_local <- function(pkg = ".",

pkg <- section_init(pkg, depth = 0, override = override)

rule("Building pkgdown site", line = "=")
cat_line("Reading from: ", src_path(path_abs(pkg$src_path)))
cat_line("Writing to: ", dst_path(path_abs(pkg$dst_path)))
cli::cli_h1("Building pkgdown site for {.pkg {pkg$package}}")
cli::cli_alert("Reading from: {src_path(path_abs(pkg$src_path))}")
cli::cli_alert("Writing to: {dst_path(path_abs(pkg$dst_path))}")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved

init_site(pkg)

Expand All @@ -447,6 +448,6 @@ build_site_local <- function(pkg = ".",
build_search(pkg, override = override)
}

rule("DONE", line = "=")
cli::cli_alert_success("finished building pkgdown site for {.pkg {pkg$package}}.")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
preview_site(pkg, preview = preview)
}
2 changes: 1 addition & 1 deletion R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ check_pkgdown <- function(pkg = ".") {
data_articles_index(pkg)
data_reference_index(pkg)

inform("No problems found")
cli::cli_alert_success("No problems found in {.file _pkgdown.yml}")
}

1 change: 1 addition & 0 deletions R/clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ clean_site <- function(pkg = ".") {
dir_delete(top_level[is_dir])
file_delete(top_level[!is_dir])

cli::cli_alert_success("Site cleaned for {.pkg {pkg$package}} (emptied {.path {pkg$dst_path}})")
jayhesselberth marked this conversation as resolved.
Show resolved Hide resolved
invisible(TRUE)
}
Loading
Loading