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()]
2
11
# '
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.
6
12
# ' @param file (string) A filename to save the statement to. Defaults to
7
13
# ' `"metadata.md"`.
8
14
# ' @param overwrite (logical) Should any existing file with this name be
9
15
# ' overwritten? Defaults to `FALSE`.
16
+ # '
10
17
# ' @returns Does not return an object to the workspace; called for the
11
18
# ' 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
+ # '
12
25
# ' @importFrom glue glue
13
26
# ' @importFrom paperbark write_md
14
27
# ' @importFrom rlang abort
28
+ # ' @importFrom cli cli_progress_step
29
+ # ' @importFrom cli cli_progress_done
30
+ # ' @importFrom cli cli_bullets
15
31
# ' @export
16
32
use_metadata <- function (file , overwrite = FALSE ){
17
33
if (missing(file )){
34
+ cli :: cli_progress_step(" Creating template file {.file metadata.md}." )
18
35
file <- " metadata.md"
36
+ cli :: cli_progress_done()
19
37
}
20
38
if (overwrite ){
39
+ cli :: cli_progress_step(" Overwriting existing file {.file {file}}." )
21
40
write_md(paperbark :: metadata_example , file = file )
41
+ cli :: cli_progress_done()
22
42
}else {
23
43
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 )
26
50
}else {
27
51
write_md(paperbark :: metadata_example , file = file )
28
52
}
29
53
}
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
+
30
63
}
0 commit comments