Skip to content

Commit 3046fde

Browse files
boshekjennybc
authored andcommitted
use_template() no longer errors when a user chooses not to overwrite an existing file and instead produces a message (#350)
* a negative user response to overwriting a file produces a message instead of an error. Closes #348 * only modify if open = TRUE and the file is actually created * modify test_that names to reflect warnings * use longer form comparison * skip R 3.1 when testing message for use_readme overwrite * Tweak docs Also a test to see if I can push to boshek/master * Swap an if-else * These functions have moved * Use `done()` instead of `message()` * Add expectations for file or dir in the project * Finish adjusting to new behaviour or write_over() and use_template()
1 parent 3e7fe14 commit 3046fde

30 files changed

+121
-114
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# usethis 1.3.0.9000
22

3+
* `use_template()` no longer errors when a user chooses not to overwrite an existing file and simply exits with confirmation that the file is unchanged (#348, @boshek).
4+
35
* `proj_sitrep()` is a new function that reports current working directory, the active usethis project, and the active RStudio Project. Call this function if things seem weird and you're not sure what's wrong or how to fix it (#426).
46

57
* usethis has a new logo! (#429)

R/ci.R

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ NULL
2222
use_travis <- function(browse = interactive()) {
2323
check_uses_github()
2424

25-
use_template(
25+
new <- use_template(
2626
"travis.yml",
2727
".travis.yml",
2828
ignore = TRUE
2929
)
30+
if (!new) return(invisible(FALSE))
3031

3132
travis_activate(browse)
3233
use_travis_badge()
33-
3434
invisible(TRUE)
3535
}
3636

@@ -81,26 +81,25 @@ use_coverage <- function(type = c("codecov", "coveralls")) {
8181

8282
use_dependency("covr", "Suggests")
8383

84-
switch(type,
85-
codecov = {
86-
use_template("codecov.yml", ignore = TRUE)
87-
use_codecov_badge()
88-
todo("Add to {value('.travis.yml')}:")
89-
code_block(
90-
"after_success:",
91-
" - Rscript -e 'covr::codecov()'"
92-
)
93-
},
94-
95-
coveralls = {
96-
todo("Turn on coveralls for this repo at https://coveralls.io/repos/new")
97-
use_coveralls_badge()
98-
todo("Add to {value('.travis.yml')}:")
99-
code_block(
100-
"after_success:",
101-
" - Rscript -e 'covr::coveralls()'"
102-
)
103-
}
84+
if (type == "codecov") {
85+
new <- use_template("codecov.yml", ignore = TRUE)
86+
if (!new) return(invisible(FALSE))
87+
}
88+
89+
if (type == "coveralls") {
90+
todo("Turn on coveralls for this repo at https://coveralls.io/repos/new")
91+
}
92+
93+
switch(
94+
type,
95+
codecov = use_codecov_badge(),
96+
coveralls = use_coveralls_badge()
97+
)
98+
99+
todo("Add to {value('.travis.yml')}:")
100+
code_block(
101+
"after_success:",
102+
" - Rscript -e 'covr::{type}()'"
104103
)
105104

106105
invisible(TRUE)
@@ -133,7 +132,8 @@ use_coveralls_badge <- function() {
133132
use_appveyor <- function(browse = interactive()) {
134133
check_uses_github()
135134

136-
use_template("appveyor.yml", ignore = TRUE)
135+
new <- use_template("appveyor.yml", ignore = TRUE)
136+
if (!new) return(invisible(FALSE))
137137

138138
appveyor_activate(browse)
139139
use_appveyor_badge()

R/code-of-conduct.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use_code_of_conduct <- function(path = NULL) {
1818
}
1919
save_as <- path_join(c(path, "CODE_OF_CONDUCT.md"))
2020

21-
use_template(
21+
new <- use_template(
2222
"CODE_OF_CONDUCT.md",
2323
save_as = save_as,
2424
ignore = is_package() && is.null(path)
@@ -30,4 +30,6 @@ use_code_of_conduct <- function(path = NULL) {
3030
"[Contributor Code of Conduct]({save_as}). ",
3131
"By contributing to this project, you agree to abide by its terms."
3232
))
33+
34+
invisible(new)
3335
}

R/cran.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,4 @@ use_cran_comments <- function(open = interactive()) {
1717
ignore = TRUE,
1818
open = open
1919
)
20-
21-
invisible(TRUE)
2220
}

R/pipe.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use_pipe <- function() {
1313
}
1414

1515
use_dependency("magrittr", "Imports")
16-
use_template("pipe.R", "R/utils-pipe.R")
17-
16+
new <- use_template("pipe.R", "R/utils-pipe.R")
1817
todo("Run {code('devtools::document()')}")
18+
invisible(new)
1919
}

R/readme.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ use_readme_rmd <- function(open = interactive()) {
2727
data <- project_data()
2828
data$Rmd <- TRUE
2929

30-
use_template(
30+
new <- use_template(
3131
if (is_package()) "package-README" else "project-README",
3232
"README.Rmd",
3333
data = data,
3434
ignore = TRUE,
3535
open = open
3636
)
37+
if (!new) return(invisible(FALSE))
3738

3839
if (uses_git()) {
3940
use_git_hook(

R/revdep.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ use_revdep <- function() {
1818
"library.noindex", "data.sqlite", "*.html")
1919
)
2020

21-
use_template(
21+
new <- use_template(
2222
"revdep-email.yml",
2323
"revdep/email.yml"
2424
)
2525

2626
todo("Run checks with {code('revdepcheck::revdep_check(num_workers = 4)')}")
27+
invisible(new)
2728
}

R/rstudio.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
#' @export
1414
use_rstudio <- function() {
1515
rproj_file <- path_ext_set(project_name(), "Rproj")
16-
use_template("template.Rproj", rproj_file)
16+
new <- use_template("template.Rproj", rproj_file)
1717

1818
use_git_ignore(".Rproj.user")
1919
if (is_package()) {
2020
use_build_ignore(c(rproj_file, ".Rproj.user"))
2121
}
2222

23-
invisible(TRUE)
23+
invisible(new)
2424
}
2525

2626
#' Don't save/load user workspace between sessions

R/template.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' the `data` argument. Internally, this function uses
1414
#' [whisker::whisker.render()] to combine your template file with your data.
1515
#'
16-
#' @param template Path to template file relative to `"templates"` directory
16+
#' @param template Path to template file relative to `templates/` directory
1717
#' within `package`; see details.
1818
#' @param save_as Name of file to create. Defaults to `template`
1919
#' @param data A list of data passed to the template.
@@ -45,7 +45,7 @@ use_template <- function(template,
4545
use_build_ignore(save_as)
4646
}
4747

48-
if (open) {
48+
if (open && new) {
4949
edit_file(proj_path(save_as))
5050
}
5151

R/test.R

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use_testthat <- function() {
2020
"tests/testthat.R",
2121
data = list(name = project_name())
2222
)
23-
24-
invisible(TRUE)
2523
}
2624

2725
#' @rdname use_testthat
@@ -43,16 +41,15 @@ use_test <- function(name = NULL, open = interactive()) {
4341
if (open) {
4442
edit_file(proj_path(path))
4543
}
46-
} else {
47-
use_template(
48-
"test-example.R",
49-
path,
50-
data = list(test_name = path_ext_remove(name)),
51-
open = open
52-
)
44+
return(invisible(TRUE))
5345
}
5446

55-
invisible(TRUE)
47+
use_template(
48+
"test-example.R",
49+
path,
50+
data = list(test_name = path_ext_remove(name)),
51+
open = open
52+
)
5653
}
5754

5855
uses_testthat <- function(base_path = proj_get()) {

0 commit comments

Comments
 (0)