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 in messages #1928

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d6b9443
Move ui_functions to cli (values with use double quotes now)
olivroy Dec 6, 2023
0c2a2f9
Use non-breaking space as a hack for indentation for multilines alerts.
olivroy Dec 6, 2023
a0c9590
Various fixups
olivroy Dec 6, 2023
13b983d
Update tests
olivroy Dec 6, 2023
a0f60d2
Update snapshots
olivroy Dec 6, 2023
ef25995
Add news
olivroy Dec 6, 2023
2368dfc
temp workaround for ci
olivroy Dec 6, 2023
7cac071
temp workaround for ci
olivroy Dec 6, 2023
b551555
drop trying to have a red bullet
olivroy Dec 6, 2023
156093d
Remove yellow from ui_info.
olivroy Dec 6, 2023
cda2894
Fixup links
olivroy Dec 6, 2023
ddbf876
move cpp11 and decor to suggests
olivroy Dec 7, 2023
be8a0f0
Add clickable urls (and convert unclickable path to .val!
olivroy Dec 7, 2023
69e7b82
Revert unnecessary changes
olivroy Dec 7, 2023
f4071f1
Add .url to documentation of data + gh homepage.
olivroy Dec 8, 2023
35480a0
Add link to NEWS.md when it exists, remove it when it doesn't.
olivroy Dec 12, 2023
616e502
add link to PR
olivroy Jan 13, 2024
f00d853
Respond to a bug encountered with `usethis::git_sitrep()` that the te…
olivroy Jan 14, 2024
661d84c
Merged upstream/main into cli
olivroy Jan 17, 2024
199bbf8
Use cli_bullets to copy the style of line breaks for multiline ui_todo.
olivroy Jan 17, 2024
edbab37
Respect usethis.quiet.
olivroy Jan 17, 2024
c095f08
Respect usethis.quiet.
olivroy Jan 17, 2024
5d64cec
Merge branch 'cli' of https://github.com/olivroy/usethis into cli
olivroy Jan 17, 2024
f717215
reuse is_quiet
olivroy Jan 17, 2024
0e9b0a2
Merge main
olivroy Feb 13, 2024
94b2ed8
Adjust config + use cli_inform instead of cli_alert.
olivroy Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions DESCRIPTION
Expand Up @@ -24,7 +24,6 @@ Depends:
Imports:
cli (>= 3.0.1),
clipr (>= 0.3.0),
crayon,
curl (>= 2.7),
desc (>= 1.4.2),
fs (>= 1.3.0),
Expand All @@ -43,7 +42,7 @@ Imports:
whisker,
withr (>= 2.3.0),
yaml
Suggests:
Suggests:
covr,
knitr,
magick,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,5 +1,7 @@
# usethis (development version)

* usethis now uses cli internally for its messaging. (#956, @olivroy)

# usethis 2.2.2

* Implicit usage of `numeric_version()` via comparison now always provides
Expand Down
25 changes: 12 additions & 13 deletions R/author.R
Expand Up @@ -61,11 +61,11 @@ use_author <- function(given = NULL, family = NULL, ..., role = "ctb") {
aut_fmt <- format(author, style = 'text')
if (authors_at_r_already) {
ui_done("
Adding to {ui_field('Authors@R')} in DESCRIPTION:
Adding to {ui_field('Authors@R')} in DESCRIPTION:\f
{aut_fmt}")
} else {
ui_done("
Creating {ui_field('Authors@R')} field in DESCRIPTION and adding:
Creating {ui_field('Authors@R')} field in DESCRIPTION and adding:\f
{aut_fmt}")
}
d$add_author(given = given, family = family, role = role, ...)
Expand All @@ -84,15 +84,14 @@ challenge_legacy_author_fields <- function(d = proj_desc()) {
return(invisible())
}

ui_oops("
Found legacy {ui_field('Author')} and/or {ui_field('Maintainer')} field \\
in DESCRIPTION.
usethis only supports modification of the {ui_field('Authors@R')} field.")
ui_info("
We recommend one of these paths forward:
* Delete these fields and rebuild with {ui_code('use_author()')}.
* Convert to {ui_field('Authors@R')} with {ui_code('desc::desc_coerce_authors_at_r()')},
then delete the legacy fields.")
ui_oops(c("Found legacy {ui_field('Author')} and/or {ui_field('Maintainer')} field in DESCRIPTION.",
"usethis only supports modification of the {ui_field('Authors@R')} field."))
ui_info(c(
"We recommend one of these paths forward:",
"*" = "Delete these fields and rebuild with {.run usethis::use_author()}.",
"*" = "Convert to {ui_field('Authors@R')} with {.fn desc::desc_coerce_authors_at_r},
\f\u00a0\u00a0 then delete the legacy fields."
))
if (ui_yeah("Do you want to cancel this operation and sort that out first?")) {
ui_stop("Cancelling.")
}
Expand Down Expand Up @@ -130,8 +129,8 @@ challenge_default_author <- function(d = proj_desc()) {

if (any(m)) {
ui_info("
{ui_field('Authors@R')} appears to include a placeholder author:
{format(default_author, style = 'text')}")
{ui_field('Authors@R')} appears to include a placeholder author:\f
{format({default_author}, style = 'text')}")
if(is_interactive() && ui_yeah("Would you like to remove it?")) {
# TODO: Do I want to suppress this output?
# Authors removed: First Last, NULL NULL.
Expand Down
4 changes: 2 additions & 2 deletions R/badge.R
Expand Up @@ -45,7 +45,7 @@ use_badge <- function(badge_name, href, src) {
if (is.null(path)) {
ui_oops("
Can't find a README for the current project.
See {ui_code('usethis::use_readme_rmd()')} for help creating this file.
See {.help usethis::use_readme_rmd} for help creating this file.
Badge link can only be printed to screen.
")
path <- "README"
Expand All @@ -59,7 +59,7 @@ use_badge <- function(badge_name, href, src) {
)

if (changed && path_ext(path) == "Rmd") {
ui_todo("Re-knit {ui_path(path)} with {ui_code('devtools::build_readme()')}")
ui_todo("Re-knit {ui_path(path)} with {.run devtools::build_readme()}")
}
invisible(changed)
}
Expand Down
2 changes: 1 addition & 1 deletion R/create.R
Expand Up @@ -89,7 +89,7 @@ create_project <- function(path,
} else {
ui_done("Writing a sentinel file {ui_path('.here')}")
ui_todo("Build robust paths within your project via {ui_code('here::here()')}")
ui_todo("Learn more at <https://here.r-lib.org>")
ui_todo("Learn more at {.url https://here.r-lib.org}")
file_create(proj_path(".here"))
}

Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Expand Up @@ -68,7 +68,7 @@ use_data <- function(...,
check_files_absent(proj_path(paths), overwrite = overwrite)

ui_done("Saving {ui_value(unlist(objs))} to {ui_value(paths)}")
if (!internal) ui_todo("Document your data (see {ui_value('https://r-pkgs.org/data.html')})")
if (!internal) ui_todo("Document your data (see {.url https://r-pkgs.org/data.html})")

envir <- parent.frame()
mapply(
Expand Down
4 changes: 1 addition & 3 deletions R/git-default-branch.R
Expand Up @@ -529,9 +529,7 @@ challenge_non_default_branch <- function(details = "Are you sure you want to pro
}

report_fishy_files <- function(old_name = "master", new_name = "main") {
ui_todo("
Be sure to update files that refer to the default branch by name.
Consider searching within your project for {ui_value(old_name)}.")
ui_todo("Be sure to update files that refer to the default branch by name. Consider searching within your project for {ui_value(old_name)}.")
# I don't want failure of a fishy file check to EVER cause
# git_default_branch_rename() to fail and prevent the call to
# git_default_branch_rediscover()
Expand Down
5 changes: 3 additions & 2 deletions R/github-actions.R
Expand Up @@ -121,7 +121,7 @@ use_github_action <- function(name = NULL,
}

if (!is.null(readme)) {
ui_todo("Learn more at <{readme}>.")
ui_todo("Learn more at {.url {readme}}.")
}

badge <- badge %||% is_check_action(url)
Expand Down Expand Up @@ -215,7 +215,7 @@ use_github_actions_badge <- function(name = "R-CMD-check.yaml",
use_tidy_github_actions <- function(ref = NULL) {
repo_spec <- target_repo_spec()

use_github_action("check-full.yaml", ref = ref, badge = TRUE)
use_github_action("check-full", ref = ref, badge = TRUE)

use_github_action("pr-commands", ref = ref)
use_github_action("pkgdown", ref = ref)
Expand All @@ -231,6 +231,7 @@ use_tidy_github_actions <- function(ref = NULL) {
"Remove existing {ui_path('.travis.yml')} and {ui_path('appveyor.yml')}?"
)) {
file_delete(old_configs[has_appveyor_travis])
# TODO maybe add ui_path("README.Rmd") or ui_path("README.md")?
ui_todo("Remove old badges from README")
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/github.R
Expand Up @@ -153,7 +153,7 @@ use_github <- function(organisation = NULL,
)
withr::defer(view_url(create$html_url))

ui_done("Setting remote {ui_value('origin')} to {ui_value(origin_url)}")
ui_done("Setting remote {ui_value('origin')} to {.url {origin_url}}")
use_git_remote("origin", origin_url)

if (is_package()) {
Expand Down
8 changes: 4 additions & 4 deletions R/helpers.R
Expand Up @@ -58,7 +58,7 @@ use_dependency <- function(package, type, min_version = NULL) {
# don't downgrade
ui_warn(
"Package {ui_value(package)} is already listed in \\
{ui_value(existing_type)} in DESCRIPTION, no change made."
{ui_field(existing_type)} in {ui_path('DESCRIPTION')}, no change made."
)
} else if (delta == 0 && !is.null(min_version)) {
# change version
Expand All @@ -67,7 +67,7 @@ use_dependency <- function(package, type, min_version = NULL) {
if (upgrade) {
ui_done(
"Increasing {ui_value(package)} version to {ui_value(version)} in \\
DESCRIPTION")
{ui_path('DESCRIPTION')}")
desc$set_dep(package, type, version = version)
desc$write()
changed <- TRUE
Expand Down Expand Up @@ -99,10 +99,10 @@ version_spec <- function(x) {
view_url <- function(..., open = is_interactive()) {
url <- paste(..., sep = "/")
if (open) {
ui_done("Opening URL {ui_value(url)}")
ui_done("Opening URL {.url {url}}")
utils::browseURL(url)
} else {
ui_todo("Open URL {ui_value(url)}")
ui_todo("Open URL {.url {url}}")
}
invisible(url)
}
15 changes: 9 additions & 6 deletions R/lifecycle.R
Expand Up @@ -34,12 +34,15 @@ use_lifecycle <- function() {
purrr::walk(templ_files, file_copy, dest_dir, overwrite = TRUE)
ui_done("Copied SVG badges to {ui_path(dest_dir)}")

ui_todo(c(
"Add badges in documentation topics by inserting one of:",
"#' `r lifecycle::badge('experimental')`",
"#' `r lifecycle::badge('superseded')`",
"#' `r lifecycle::badge('deprecated')`"
))
ui_todo("Add badges in documentation topics by inserting one of:")
if (!is_quiet()) {
# to preserve white spaces
cli::cli_bullets(c(
" " = "#' `r lifecycle::badge('experimental')`",
" " = "#' `r lifecycle::badge('superseded')`",
" " = "#' `r lifecycle::badge('deprecated')`"
))
}

invisible(TRUE)
}
4 changes: 2 additions & 2 deletions R/news.R
Expand Up @@ -50,10 +50,10 @@ use_news_heading <- function(version) {
if (development_title == news[[1]]) {
news[[1]] <- title

ui_done("Replacing development heading in NEWS.md")
ui_done("Replacing development heading in {.file NEWS.md}")
return(write_utf8(news_path, news))
}

ui_done("Adding new heading to NEWS.md")
ui_done("Adding new heading to {.file NEWS.md}")
write_utf8(news_path, c(title, "", news))
}
4 changes: 2 additions & 2 deletions R/package.R
Expand Up @@ -169,12 +169,12 @@ suggests_usage_hint <- function(package) {
code2 <- glue('rlang::check_installed("{package}")')
ui_todo("
In your package code, use {ui_code(code1)} or {ui_code(code2)} to test \\
if {package} is installed")
if {package} is installed.")
code <- glue("{package}::fun()")
ui_todo("Then directly refer to functions with {ui_code(code)}")
} else {
code <- glue("requireNamespace(\"{package}\", quietly = TRUE)")
ui_todo("Use {ui_code(code)} to test if package is installed")
ui_todo("Use {ui_code(code)} to test if {package} is installed.")
code <- glue("{package}::fun()")
ui_todo("Then directly refer to functions with {ui_code(code)}")
}
Expand Down
2 changes: 1 addition & 1 deletion R/pkgdown.R
Expand Up @@ -106,7 +106,7 @@ use_pkgdown_url <- function(url, tr = NULL) {
gh <- gh_tr(tr)
homepage <- gh("GET /repos/{owner}/{repo}")[["homepage"]]
if (is.null(homepage) || homepage != url) {
ui_done("Setting {ui_value(url)} as homepage of GitHub repo \\
ui_done("Setting {.url {url}} as homepage of GitHub repo \\
{ui_value(tr$repo_spec)}")
gh("PATCH /repos/{owner}/{repo}", homepage = url)
}
Expand Down
2 changes: 1 addition & 1 deletion R/pr.R
Expand Up @@ -401,7 +401,7 @@ pr_push <- function() {
pr_create()
} else {
ui_todo("
View PR at {ui_value(pr$pr_html_url)} or call {ui_code('pr_view()')}.")
View PR at {.url {pr$pr_html_url}} or call {.run usethis::pr_view()}.")
}

invisible()
Expand Down
2 changes: 1 addition & 1 deletion R/release.R
Expand Up @@ -391,7 +391,7 @@ get_release_news <- function(SHA = gert::git_info(repo = git_repo())$commit,

if (is.null(news)) {
ui_oops("
Can't find {ui_path('NEWS.md')} in the released package source.
Can't find {.val NEWS.md} in the released package source.
usethis consults this file for release notes.
Call {ui_code('usethis::use_news_md()')} to set this up for the future.")
if (on_cran) "-- no release notes --" else "Initial release"
Expand Down