Skip to content

Commit 758dfd7

Browse files
committed
Apply the package to itself:
stamp_dir("R", template = "agpl-3", recursive = TRUE, action="modify", copyright = "2025", author = "James J Balamuta")
1 parent 1e84ed7 commit 758dfd7

11 files changed

+226
-39
lines changed

R/language-support.R

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (c) 2025
2+
# Author: James J Balamuta
3+
# License: GNU Affero General Public License v3.0 or later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published
7+
# by the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
118
#' Register a new language
219
#'
320
#' @param name Character. Language name.
@@ -8,7 +25,7 @@
825
#'
926
#' @return stamp_language object, invisibly.
1027
#' @export
11-
language_register <- function(name, extensions, comment_single,
28+
language_register <- function(name, extensions, comment_single,
1229
comment_multi_start = NULL, comment_multi_end = NULL) {
1330
lang <- structure(
1431
list(
@@ -20,11 +37,11 @@ language_register <- function(name, extensions, comment_single,
2037
),
2138
class = "stamp_language"
2239
)
23-
40+
2441
langs <- getOption("filestamp.languages", list())
2542
langs[[name]] <- lang
2643
options(filestamp.languages = langs)
27-
44+
2845
invisible(lang)
2946
}
3047

@@ -36,11 +53,11 @@ language_register <- function(name, extensions, comment_single,
3653
#' @export
3754
language_get <- function(name) {
3855
langs <- getOption("filestamp.languages", list())
39-
56+
4057
if (!name %in% names(langs)) {
4158
cli::cli_abort("Language not found: {name}")
4259
}
43-
60+
4461
langs[[name]]
4562
}
4663

@@ -60,16 +77,16 @@ languages <- function() {
6077
#' @export
6178
detect_language <- function(file) {
6279
ext <- tolower(tools::file_ext(file))
63-
80+
6481
langs <- languages()
65-
82+
6683
for (lang_name in names(langs)) {
6784
lang <- langs[[lang_name]]
6885
if (ext %in% lang$extensions) {
6986
return(lang)
7087
}
7188
}
72-
89+
7390
# Default to plain text
7491
language_get("text")
7592
}
@@ -84,7 +101,7 @@ detect_language <- function(file) {
84101
format_header <- function(content, language) {
85102
# Ensure content is properly split into lines
86103
lines <- unlist(strsplit(content, "\n"))
87-
104+
88105
if (!is.null(language$comment_multi_start) && !is.null(language$comment_multi_end)) {
89106
# Use multi-line comments
90107
paste0(

R/printers.R

+41-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (c) 2025
2+
# Author: James J Balamuta
3+
# License: GNU Affero General Public License v3.0 or later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published
7+
# by the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
118
#' Print method for templates
219
#'
320
#' @param x stamp_template object.
@@ -8,18 +25,18 @@
825
#' @method print stamp_template
926
print.stamp_template <- function(x, ...) {
1027
cli::cli_h1("Template: {x$name}")
11-
28+
1229
cli::cli_h2("Fields:")
1330
for (field_name in names(x$fields)) {
1431
field <- x$fields[[field_name]]
1532
default <- if (is.null(field$default)) "<none>" else field$default
1633
required <- if (field$required) "Required" else "Optional"
1734
cli::cli_li("{field_name}: {default} ({required})")
1835
}
19-
36+
2037
cli::cli_h2("Content:")
2138
cli::cli_code(x$content)
22-
39+
2340
invisible(x)
2441
}
2542

@@ -33,10 +50,10 @@ print.stamp_template <- function(x, ...) {
3350
#' @method print stamp_preview
3451
print.stamp_preview <- function(x, ...) {
3552
cli::cli_h1("Preview for: {x$file}")
36-
53+
3754
cli::cli_h2("Header to be inserted:")
3855
cli::cli_code(x$header)
39-
56+
4057
cli::cli_h2("Insertion point:")
4158
if (x$insert_position == 0) {
4259
cli::cli_text("Beginning of file")
@@ -45,12 +62,12 @@ print.stamp_preview <- function(x, ...) {
4562
} else {
4663
cli::cli_text("Line {x$insert_position}")
4764
}
48-
65+
4966
cli::cli_h2("File properties:")
5067
cli::cli_li("Encoding: {x$encoding}")
5168
cli::cli_li("Line ending: {if (x$line_ending == '\n') 'LF' else if (x$line_ending == '\r') 'CR' else 'CRLF'}")
5269
cli::cli_li("Read-only: {if (x$read_only) 'Yes' else 'No'}")
53-
70+
5471
invisible(x)
5572
}
5673

@@ -64,19 +81,19 @@ print.stamp_preview <- function(x, ...) {
6481
#' @method print stamp_language
6582
print.stamp_language <- function(x, ...) {
6683
cli::cli_h1("Language: {x$name}")
67-
84+
6885
cli::cli_h2("File extensions:")
6986
extensions <- paste(x$extensions, collapse = ", ")
7087
cli::cli_text(extensions)
71-
88+
7289
cli::cli_h2("Comment style:")
7390
cli::cli_li("Single line: {x$comment_single}")
74-
91+
7592
if (!is.null(x$comment_multi_start) && !is.null(x$comment_multi_end)) {
7693
cli::cli_li("Multi-line start: {x$comment_multi_start}")
7794
cli::cli_li("Multi-line end: {x$comment_multi_end}")
7895
}
79-
96+
8097
invisible(x)
8198
}
8299

@@ -90,25 +107,25 @@ print.stamp_language <- function(x, ...) {
90107
#' @method print stamp_dir_results
91108
print.stamp_dir_results <- function(x, ...) {
92109
cli::cli_h1("Directory Stamping Results: {x$dir}")
93-
110+
94111
cli::cli_h2("Action: {x$action}")
95-
112+
96113
success_count <- sum(sapply(x$results, function(r) r$status == "success"))
97114
error_count <- sum(sapply(x$results, function(r) r$status == "error"))
98-
115+
99116
cli::cli_alert_success("{success_count} files successfully processed")
100-
117+
101118
if (error_count > 0) {
102119
cli::cli_alert_danger("{error_count} files had errors")
103-
120+
104121
cli::cli_h2("Errors:")
105122
for (result in x$results) {
106123
if (result$status == "error") {
107124
cli::cli_li("{result$file}: {result$message}")
108125
}
109126
}
110127
}
111-
128+
112129
invisible(x)
113130
}
114131

@@ -122,11 +139,11 @@ print.stamp_dir_results <- function(x, ...) {
122139
#' @method print stamp_file_info
123140
print.stamp_file_info <- function(x, ...) {
124141
cli::cli_h1("File Information: {x$path}")
125-
142+
126143
cli::cli_li("Encoding: {x$encoding}")
127144
cli::cli_li("Line ending: {if (x$line_ending == '\n') 'LF' else if (x$line_ending == '\r') 'CR' else 'CRLF'}")
128145
cli::cli_li("Read-only: {if (x$read_only) 'Yes' else 'No'}")
129-
146+
130147
invisible(x)
131148
}
132149

@@ -140,19 +157,19 @@ print.stamp_file_info <- function(x, ...) {
140157
#' @method print stamp_update_preview
141158
print.stamp_update_preview <- function(x, ...) {
142159
cli::cli_h1("Update Preview for: {x$file}")
143-
160+
144161
cli::cli_h2("Updated fields:")
145162
for (field_name in names(x$fields)) {
146163
cli::cli_li("{field_name}: {x$fields[[field_name]]}")
147164
}
148-
165+
149166
cli::cli_h2("Header location:")
150167
cli::cli_text("Lines {x$range[1]} to {x$range[2]}")
151-
168+
152169
cli::cli_h2("File properties:")
153170
cli::cli_li("Encoding: {x$encoding}")
154171
cli::cli_li("Line ending: {if (x$line_ending == '\n') 'LF' else if (x$line_ending == '\r') 'CR' else 'CRLF'}")
155172
cli::cli_li("Read-only: {if (x$read_only) 'Yes' else 'No'}")
156-
173+
157174
invisible(x)
158-
}
175+
}

R/stamp-dir.R

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (c) 2025
2+
# Author: James J Balamuta
3+
# License: GNU Affero General Public License v3.0 or later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published
7+
# by the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
118
#' Stamp all files in a directory with a header
219
#'
320
#' @param dir Character. Path to directory to stamp.

R/stamp-file.R

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (c) 2025
2+
# Author: James J Balamuta
3+
# License: GNU Affero General Public License v3.0 or later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published
7+
# by the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
118
#' Stamp a single file with a header
219
#'
320
#' @param file Character. Path to file to stamp.

R/stamp-template.R

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (c) 2025
2+
# Author: James J Balamuta
3+
# License: GNU Affero General Public License v3.0 or later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published
7+
# by the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
118
#' Create a new template
219
#'
320
#' @param name Character. Name of template.

R/stamp-update.R

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (c) 2025
2+
# Author: James J Balamuta
3+
# License: GNU Affero General Public License v3.0 or later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published
7+
# by the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
118
#' Update existing file headers
219
#'
320
#' @param file Character. Path to file to update.

R/stamp-variables.R

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (c) 2025
2+
# Author: James J Balamuta
3+
# License: GNU Affero General Public License v3.0 or later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published
7+
# by the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
118
#' Get built-in variables
219
#'
320
#' @return Environment with built-in variables.

R/stamp.R

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (c) 2025
2+
# Author: James J Balamuta
3+
# License: GNU Affero General Public License v3.0 or later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as published
7+
# by the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
118
#' Stamp a file or directory with a header
219
#'
320
#' This is the main entry point for the filestamp package. It automatically

0 commit comments

Comments
 (0)