Skip to content

Commit 6fee8c7

Browse files
committed
Improve di_*() instruction documentation
1 parent 9160879 commit 6fee8c7

File tree

4 files changed

+183
-18
lines changed

4 files changed

+183
-18
lines changed

R/dockerignore-instructions.R

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
#' Add patterns to a dockerignore object
22
#'
3-
#' @param dockerignore A dockerignore object
4-
#' @param pattern Character vector of patterns to add
5-
#' @return Updated dockerignore object
3+
#' Adds one or more patterns to a `dockerignore` object, avoiding duplicates.
4+
#'
5+
#' @param dockerignore A `dockerignore` object
6+
#' @param pattern Character vector of patterns to add
7+
#'
8+
#' @return
9+
#' An updated `dockerignore` object with the new patterns added
10+
#'
11+
#' @examples
12+
#' di <- dockerignore()
13+
#'
14+
#' # Add a single pattern
15+
#' di <- di_add(di, ".git/")
16+
#'
17+
#' # Add multiple patterns
18+
#' di <- di_add(di, c("*.log", "node_modules/", "*.tmp"))
19+
#'
20+
#' @details
21+
#' Patterns follow the same syntax as `.gitignore` files:
22+
#' * Lines starting with `#` are comments
23+
#' * Blank lines are ignored
24+
#' * Trailing slashes `/` specify directories
25+
#' * Patterns with special characters like `*`, `?`, and `[]` use glob syntax
26+
#' * Lines starting with `!` negate a pattern (include a file that would otherwise be ignored)
27+
#'
28+
#' @seealso
29+
#' [di_remove()] for removing patterns &
30+
#' [di_replace()] for replacing patterns
31+
#'
32+
#' @family dockerignore instruction functions
633
#' @export
734
di_add <- function(dockerignore, pattern) {
835
check_dockerignore(dockerignore)
@@ -18,11 +45,29 @@ di_add <- function(dockerignore, pattern) {
1845
dockerignore
1946
}
2047

21-
#' Remove patterns from a dockerignore object
48+
#' Remove patterns from a `dockerignore` object
49+
#'
50+
#' Removes one or more patterns from a `dockerignore` object.
2251
#'
23-
#' @param dockerignore A dockerignore object
52+
#' @param dockerignore A `dockerignore` object
2453
#' @param pattern Character vector of patterns to remove
25-
#' @return Updated dockerignore object
54+
#'
55+
#' @return
56+
#' An updated `dockerignore` object with the specified patterns removed
57+
#'
58+
#' @examples
59+
#' # Create a dockerignore object and add some patterns
60+
#' di <- dockerignore() |>
61+
#' di_add(c(".git/", "*.log", "node_modules/"))
62+
#'
63+
#' # Remove a pattern
64+
#' di <- di_remove(di, "*.log")
65+
#'
66+
#' @seealso
67+
#' [di_add()] for adding patterns &
68+
#' [di_replace()] for replacing patterns
69+
#'
70+
#' @family dockerignore instruction functions
2671
#' @export
2772
di_remove <- function(dockerignore, pattern) {
2873
check_dockerignore(dockerignore)
@@ -35,10 +80,46 @@ di_remove <- function(dockerignore, pattern) {
3580

3681
#' Replace patterns in a dockerignore object
3782
#'
38-
#' @param dockerignore A dockerignore object
83+
#' Replaces one or more patterns in a dockerignore object with new patterns.
84+
#'
85+
#' @param dockerignore A `dockerignore` object
3986
#' @param old_pattern Pattern(s) to replace
4087
#' @param new_pattern New pattern(s)
41-
#' @return Updated dockerignore object
88+
#'
89+
#' @return
90+
#' An updated `dockerignore` object with the specified patterns replaced
91+
#'
92+
#' @examples
93+
#' # Create a dockerignore object and add some patterns
94+
#' di <- dockerignore() |>
95+
#' di_add(c("*.log", "*.tmp", "node_modules/"))
96+
#'
97+
#' # Replace a single pattern
98+
#' di <- di_replace(di, "*.log", "logs/")
99+
#'
100+
#' # Replace multiple patterns with a single pattern
101+
#' di <- di_replace(di, c("*.tmp", "node_modules/"), "temp/")
102+
#'
103+
#' # Replace patterns one-to-one
104+
#' di <- di_replace(di,
105+
#' c("*.log", "*.tmp"),
106+
#' c("logs/*", "temp/*"))
107+
#'
108+
#' @details
109+
#' This function allows you to replace patterns in a dockerignore object.
110+
#' Three modes of operation are supported:
111+
#'
112+
#' 1. Replace a single pattern with a single pattern
113+
#' 2. Replace multiple patterns with a single pattern
114+
#' 3. Replace multiple patterns with corresponding new patterns (one-to-one)
115+
#'
116+
#' For the third mode, `old_pattern` and `new_pattern` must have the same length.
117+
#'
118+
#' @seealso
119+
#' [di_add()] for adding patterns &
120+
#' [di_remove()] for removing patterns
121+
#'
122+
#' @family dockerignore instruction functions
42123
#' @export
43124
di_replace <- function(dockerignore, old_pattern, new_pattern) {
44125
check_dockerignore(dockerignore)

man/di_add.Rd

Lines changed: 32 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/di_remove.Rd

Lines changed: 22 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/di_replace.Rd

Lines changed: 40 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)