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
+
1
18
# ' Print method for templates
2
19
# '
3
20
# ' @param x stamp_template object.
8
25
# ' @method print stamp_template
9
26
print.stamp_template <- function (x , ... ) {
10
27
cli :: cli_h1(" Template: {x$name}" )
11
-
28
+
12
29
cli :: cli_h2(" Fields:" )
13
30
for (field_name in names(x $ fields )) {
14
31
field <- x $ fields [[field_name ]]
15
32
default <- if (is.null(field $ default )) " <none>" else field $ default
16
33
required <- if (field $ required ) " Required" else " Optional"
17
34
cli :: cli_li(" {field_name}: {default} ({required})" )
18
35
}
19
-
36
+
20
37
cli :: cli_h2(" Content:" )
21
38
cli :: cli_code(x $ content )
22
-
39
+
23
40
invisible (x )
24
41
}
25
42
@@ -33,10 +50,10 @@ print.stamp_template <- function(x, ...) {
33
50
# ' @method print stamp_preview
34
51
print.stamp_preview <- function (x , ... ) {
35
52
cli :: cli_h1(" Preview for: {x$file}" )
36
-
53
+
37
54
cli :: cli_h2(" Header to be inserted:" )
38
55
cli :: cli_code(x $ header )
39
-
56
+
40
57
cli :: cli_h2(" Insertion point:" )
41
58
if (x $ insert_position == 0 ) {
42
59
cli :: cli_text(" Beginning of file" )
@@ -45,12 +62,12 @@ print.stamp_preview <- function(x, ...) {
45
62
} else {
46
63
cli :: cli_text(" Line {x$insert_position}" )
47
64
}
48
-
65
+
49
66
cli :: cli_h2(" File properties:" )
50
67
cli :: cli_li(" Encoding: {x$encoding}" )
51
68
cli :: cli_li(" Line ending: {if (x$line_ending == '\n ') 'LF' else if (x$line_ending == '\r ') 'CR' else 'CRLF'}" )
52
69
cli :: cli_li(" Read-only: {if (x$read_only) 'Yes' else 'No'}" )
53
-
70
+
54
71
invisible (x )
55
72
}
56
73
@@ -64,19 +81,19 @@ print.stamp_preview <- function(x, ...) {
64
81
# ' @method print stamp_language
65
82
print.stamp_language <- function (x , ... ) {
66
83
cli :: cli_h1(" Language: {x$name}" )
67
-
84
+
68
85
cli :: cli_h2(" File extensions:" )
69
86
extensions <- paste(x $ extensions , collapse = " , " )
70
87
cli :: cli_text(extensions )
71
-
88
+
72
89
cli :: cli_h2(" Comment style:" )
73
90
cli :: cli_li(" Single line: {x$comment_single}" )
74
-
91
+
75
92
if (! is.null(x $ comment_multi_start ) && ! is.null(x $ comment_multi_end )) {
76
93
cli :: cli_li(" Multi-line start: {x$comment_multi_start}" )
77
94
cli :: cli_li(" Multi-line end: {x$comment_multi_end}" )
78
95
}
79
-
96
+
80
97
invisible (x )
81
98
}
82
99
@@ -90,25 +107,25 @@ print.stamp_language <- function(x, ...) {
90
107
# ' @method print stamp_dir_results
91
108
print.stamp_dir_results <- function (x , ... ) {
92
109
cli :: cli_h1(" Directory Stamping Results: {x$dir}" )
93
-
110
+
94
111
cli :: cli_h2(" Action: {x$action}" )
95
-
112
+
96
113
success_count <- sum(sapply(x $ results , function (r ) r $ status == " success" ))
97
114
error_count <- sum(sapply(x $ results , function (r ) r $ status == " error" ))
98
-
115
+
99
116
cli :: cli_alert_success(" {success_count} files successfully processed" )
100
-
117
+
101
118
if (error_count > 0 ) {
102
119
cli :: cli_alert_danger(" {error_count} files had errors" )
103
-
120
+
104
121
cli :: cli_h2(" Errors:" )
105
122
for (result in x $ results ) {
106
123
if (result $ status == " error" ) {
107
124
cli :: cli_li(" {result$file}: {result$message}" )
108
125
}
109
126
}
110
127
}
111
-
128
+
112
129
invisible (x )
113
130
}
114
131
@@ -122,11 +139,11 @@ print.stamp_dir_results <- function(x, ...) {
122
139
# ' @method print stamp_file_info
123
140
print.stamp_file_info <- function (x , ... ) {
124
141
cli :: cli_h1(" File Information: {x$path}" )
125
-
142
+
126
143
cli :: cli_li(" Encoding: {x$encoding}" )
127
144
cli :: cli_li(" Line ending: {if (x$line_ending == '\n ') 'LF' else if (x$line_ending == '\r ') 'CR' else 'CRLF'}" )
128
145
cli :: cli_li(" Read-only: {if (x$read_only) 'Yes' else 'No'}" )
129
-
146
+
130
147
invisible (x )
131
148
}
132
149
@@ -140,19 +157,19 @@ print.stamp_file_info <- function(x, ...) {
140
157
# ' @method print stamp_update_preview
141
158
print.stamp_update_preview <- function (x , ... ) {
142
159
cli :: cli_h1(" Update Preview for: {x$file}" )
143
-
160
+
144
161
cli :: cli_h2(" Updated fields:" )
145
162
for (field_name in names(x $ fields )) {
146
163
cli :: cli_li(" {field_name}: {x$fields[[field_name]]}" )
147
164
}
148
-
165
+
149
166
cli :: cli_h2(" Header location:" )
150
167
cli :: cli_text(" Lines {x$range[1]} to {x$range[2]}" )
151
-
168
+
152
169
cli :: cli_h2(" File properties:" )
153
170
cli :: cli_li(" Encoding: {x$encoding}" )
154
171
cli :: cli_li(" Line ending: {if (x$line_ending == '\n ') 'LF' else if (x$line_ending == '\r ') 'CR' else 'CRLF'}" )
155
172
cli :: cli_li(" Read-only: {if (x$read_only) 'Yes' else 'No'}" )
156
-
173
+
157
174
invisible (x )
158
- }
175
+ }
0 commit comments