Skip to content

Commit 1c4daa7

Browse files
committed
Improve messaging in use_metadata()
* Minor tidying to documentation
1 parent ee9126f commit 1c4daa7

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

R/use_metadata.R

+39-6
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,63 @@
1-
#' Write an example metadata statement
1+
#' Create an example metadata statement file
2+
#'
3+
#' @description
4+
#' This function creates a metadata template and exports it to the specified
5+
#' file. The template is taken from `metadata_example` (see `metadata_example`
6+
#' for documentation). The template `.md` file can act as a boilerplate metadata
7+
#' statement that you can edit yourself.
8+
#'
9+
#' The final edited file can be converted for use in a Darwin
10+
#' Core Archive using [build_metadata()]
211
#'
3-
#' This function takes `metadata_example` and exports it to the specified file.
4-
#' This is useful for creating a boilerplate metadata statement that you
5-
#' can edit yourself.
612
#' @param file (string) A filename to save the statement to. Defaults to
713
#' `"metadata.md"`.
814
#' @param overwrite (logical) Should any existing file with this name be
915
#' overwritten? Defaults to `FALSE`.
16+
#'
1017
#' @returns Does not return an object to the workspace; called for the
1118
#' side-effect of saving a markdown file to the specified location.
19+
#'
20+
#' @examples \dontrun{
21+
#' # Save template file metadata.md to local directory
22+
#' use_metadata()
23+
#' }
24+
#'
1225
#' @importFrom glue glue
1326
#' @importFrom paperbark write_md
1427
#' @importFrom rlang abort
28+
#' @importFrom cli cli_progress_step
29+
#' @importFrom cli cli_progress_done
30+
#' @importFrom cli cli_bullets
1531
#' @export
1632
use_metadata <- function(file, overwrite = FALSE){
1733
if(missing(file)){
34+
cli::cli_progress_step("Creating template file {.file metadata.md}.")
1835
file <- "metadata.md"
36+
cli::cli_progress_done()
1937
}
2038
if(overwrite){
39+
cli::cli_progress_step("Overwriting existing file {.file {file}}.")
2140
write_md(paperbark::metadata_example, file = file)
41+
cli::cli_progress_done()
2242
}else{
2343
if(file.exists(file)){
24-
abort(c(glue("file `{file}` already exists."),
25-
i = "give a different `file` or set `overwrite = TRUE`"))
44+
bullets <- c("File {.file {file}} already exists.",
45+
i = "Use a different filename or set `overwrite = TRUE`") |>
46+
cli::cli_bullets() |>
47+
cli::cli_fmt()
48+
49+
abort(bullets)
2650
}else{
2751
write_md(paperbark::metadata_example, file = file)
2852
}
2953
}
54+
55+
cli::cli_bullets(c(
56+
v = "File template {.file {file}} saved to top folder in local directory.",
57+
i = paste(
58+
c(" Edit {.file {file}}") |> cli::col_grey(),
59+
c("then use {.fn build_metadata} to build final metadata statement.") |> cli::col_grey()
60+
)
61+
))
62+
3063
}

0 commit comments

Comments
 (0)