Skip to content

Commit 3a47d0e

Browse files
authored
Merge pull request #22 from olivroy/cli
Use cli instead of crayon.
2 parents f4e0590 + 0bd348c commit 3a47d0e

File tree

7 files changed

+31
-35
lines changed

7 files changed

+31
-35
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$

DESCRIPTION

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ Description: Simple interface to query gitignore.io to fetch
2121
gitignore templates that can be included in the .gitignore file. More
2222
than 450 templates are currently available.
2323
License: GPL-3
24-
URL: https://docs.ropensci.org/gitignore/, https://github.com/ropensci/gitignore, https://github.com/ropensci/gitignore
24+
URL: https://docs.ropensci.org/gitignore/, https://github.com/ropensci/gitignore
2525
BugReports: https://github.com/ropensci/gitignore/issues
2626
Imports:
27+
cli,
2728
clipr,
28-
clisymbols,
29-
crayon,
3029
curl,
3130
glue,
3231
here,
@@ -44,4 +43,4 @@ VignetteBuilder:
4443
Encoding: UTF-8
4544
Language: en-US
4645
LazyData: true
47-
RoxygenNote: 7.2.3
46+
RoxygenNote: 7.3.1

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# gitignore (development version)
22

3+
- gitignore now provides clickable links as it uses cli instead of crayon.
4+
35
# gitignore 0.1.6
46

57
- Skip or do not execute code chunks in vignettes if the internet or the gitignore API is not available, to fix CRAN problems.
@@ -13,7 +15,7 @@
1315

1416
# gitignore 0.1.4
1517

16-
- Change backend from https://www.gitignore.io/ to https://www.toptal.com/developers/gitignore as the former now redirects to the later (#13 @pat-s).
18+
- Change backend from https://www.gitignore.io/ to https://www.toptal.com/developers/gitignore as the former now redirects to the latter (#13 @pat-s).
1719

1820
- Use `file.path()` instead of `paste0()` to build path. @dpprdan
1921

R/gi_available_templates.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ gi_available_templates <-
1515
res <- curl::curl_fetch_memory(url)
1616

1717
if (res$status_code != 200) {
18-
stop(paste("http request failed with status code:"), res$status_code)
18+
cli::cli_abort("http request failed with status code: {res$status_code}")
1919
}
2020

2121
json_text <- rawToChar(res$content)
2222

2323
if (!jsonlite::validate(json_text)) {
24-
stop("Invalid json file returned in gi_available_templates() function.")
24+
cli::cli_abort("Invalid json file returned in gi_available_templates() function.")
2525
}
2626

2727
r <- jsonlite::fromJSON(json_text)

R/gi_fetch_templates.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ gi_fetch_templates <-
4242
i <- template_name %in% l
4343

4444
if (!all(i)) {
45-
stop(
46-
"Some template_name were not found on gitignore.io: ",
47-
crayon::red$bold(paste(template_name[!i], collapse = ", "))
45+
# https://cli.r-lib.org/reference/cli_div.html
46+
cli::cli_div(theme = list(span.emph = list(color = "red", "font-weight" = "bold")))
47+
cli::cli_abort(
48+
"Some template_name were not found on gitignore.io: {.emph {template_name[!i]}}.",
4849
)
4950
}
5051

@@ -56,17 +57,15 @@ gi_fetch_templates <-
5657
)
5758

5859
if (r$status_code != 200) {
59-
stop(paste("http request failed with status code:"), r$status_code)
60+
cli::cli_abort("http request failed with status code: {r$status_code}")
6061
}
6162

6263
# Copy or not into the clipboard
6364
if (clipr::clipr_available() && copy_to_clipboard) { # nocov start
6465
clipr::write_clip(rawToChar(r$content))
65-
message(
66-
crayon::green(clisymbols::symbol$bullet),
67-
paste(
68-
" Copied to the clipboard.",
69-
"You can now paste it in your .gitignore file.\n"
66+
cli::cli_inform(c(
67+
"v" = "Copied to the clipboard.
68+
You can now paste it in your {.file .gitignore}"
7069
)
7170
) # nocov end
7271
} else {

R/gi_write_gitignore.R

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ gi_write_gitignore <-
2424
stopifnot(basename(gitignore_file) == ".gitignore")
2525

2626
if (!file.exists(gitignore_file)) { # nocov start
27-
message(
28-
crayon::red(clisymbols::symbol$bullet),
29-
" The .gitignore file could not be found in the project directory",
30-
here::here(),
31-
"Would you like to create it?",
32-
"\n"
33-
)
27+
cli::cli_inform(c(
28+
"x" = "The .gitignore file could not be found in the
29+
project directory {.path {here::here()}}",
30+
i = "Would you like to create it?"
31+
))
3432

3533
response <- utils::menu(c("Yes", "No"))
3634

@@ -39,9 +37,8 @@ gi_write_gitignore <-
3937
file.create(gitignore_file)
4038

4139
} else {
42-
stop(
43-
"Could not find the file: ",
44-
crayon::red$bold(gitignore_file)
40+
cli::cli_abort(
41+
"Could not find the file: {.file {gitignore_file}}",
4542
)
4643
}
4744
} # nocov end
@@ -54,21 +51,19 @@ gi_write_gitignore <-
5451
new <- setdiff(fetched_template_splitted, existing_lines)
5552

5653
if (length(new) == 0) {
57-
message(
58-
crayon::yellow(clisymbols::symbol$bullet),
59-
" Nothing to be modified in the .gitignore file.\n"
60-
)
54+
cli::cli_inform(c(
55+
"!" = "Nothing to be modified in the {.file .gitignore} file."
56+
))
6157
return(FALSE)
6258
}
6359

6460
all <- c(existing_lines, new)
6561

6662
xfun::write_utf8(all, gitignore_file)
6763

68-
message(
69-
crayon::green(clisymbols::symbol$bullet),
70-
" .gitignore file successfully modified.\n"
71-
)
64+
cli::cli_inform(c(
65+
"v" = "{.file .gitignore} file successfully modified."
66+
))
7267

7368
invisible(TRUE)
7469
}

man/gitignore-package.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)