gitignore_template_generator/constant.rs
1//! Define globally-shared constants.
2
3pub mod error_messages {
4 //! Constants for error messages to be displayed.
5
6 /// An error occurred during [`std::process::Command::output`].
7 pub const CMD_EXECUTION_FAILURE: &str = "Failed to execute command";
8
9 /// An error occurred during HTTP body parsing.
10 pub const BODY_PARSING_ISSUE: &str =
11 "An error occurred during body parsing";
12
13 /// An error occurred while reading a file and converting it to a String
14 /// instance.
15 pub const FILE_READ_TO_STRING_FAILURE: &str =
16 "Failed to read expected output file";
17
18 /// Commas found in cli positional args.
19 pub const COMMAS_NOT_ALLOWED: &str =
20 "Commas are not allowed in template names";
21
22 /// An error occurred during an api call.
23 pub const API_CALL_FAILURE: &str =
24 "An error occurred during the API call: {error}";
25
26 /// A HTTP error 400 occurred during api call.
27 pub const HTTP_400: &str = "http status: 400";
28
29 /// A HTTP error 404 occurred during api call.
30 pub const HTTP_404: &str = "http status: 404";
31
32 /// User requested author infos but none is available.
33 pub const AUTHOR_INFOS_NOT_AVAILABLE: &str =
34 "Author information not available.";
35
36 /// User requested version infos but none is available.
37 pub const VERSION_INFOS_NOT_AVAILABLE: &str =
38 "Version information not available.";
39
40 /// `White_Space` found in cli positional args.
41 ///
42 /// `White_Space` is specified in the
43 /// [Unicode Character Database][ucd] [`PropList.txt`].
44 ///
45 /// [ucd]: https://www.unicode.org/reports/tr44/
46 /// [`PropList.txt`]: https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt
47 pub const WHITESPACES_NOT_ALLOWED: &str =
48 "Whitespace characters are not allowed in template names";
49
50 // One or more template names are not supported.
51 pub const INEXISTENT_TEMPLATE_NAMES: &str = "Following template names are not supported: {templates}.\nFor the list of available template names, try '--list'.";
52
53 // Conversion of String to u64.
54 pub const FAILED_U64_CONVERSION: &str = "Failed to convert to u64";
55
56 /// Timeout for current HTTP call.
57 pub const TIMEOUT: &str = "timeout: global";
58
59 /// Invalid utf-8 encoding.
60 pub const INVALID_ENCODING: &str = "io: stream did not contain valid UTF-8";
61
62 /// No slash in front of URI.
63 pub const URI_WITHOUT_STARTING_SLASH: &str = "URIs must start a slash (/)";
64
65 /// Invalid URL.
66 pub const INVALID_URL: &str = "Value must be a valid URL";
67
68 pub const LOCAL_GENERATION: &str =
69 "An error occurred while generating template from local file system";
70
71 pub const LOCAL_LISTING: &str =
72 "An error occurred while listing templates from local file system";
73
74 pub const UNSUPPORTED_TEMPLATE: &str = "One or more provided template names are not supported\nTo enable robust template names check, retry with '--check'.\nFor the list of available template names, try '--list'.";
75}
76
77pub mod help_messages {
78 //! Constants for help messages to be displayed.
79
80 /// Help message bound to [`crate::parser::Args::template_names`]
81 /// field (i.e. positional args).
82 pub const TEMPLATE_NAMES: &str =
83 "A non-empty list of gitignore template names";
84
85 /// Help message bound to [`crate::parser::Args::show_author`]
86 /// field (i.e. author option).
87 pub const AUTHOR: &str = "Print author";
88
89 /// Help message bound to [`crate::parser::Args::server_url`]
90 /// field (i.e. server url option).
91 pub const SERVER_URL: &str = "The template manager url";
92
93 /// Help message bound to [`crate::parser::Args::show_help`]
94 /// field (i.e. help option).
95 pub const HELP: &str = "Print help";
96
97 /// Help message bound to [`crate::parser::Args::show_version`]
98 /// field (i.e. version option).
99 pub const VERSION: &str = "Print version";
100
101 /// Help message bound to [`crate::parser::Args::generator_uri`]
102 /// field (i.e. generator uri option).
103 pub const GENERATOR_URI: &str = "The template generator uri";
104
105 /// Help message bound to [`crate::parser::Args::show_list`]
106 /// field (i.e. list option).
107 pub const LIST: &str = "List available templates";
108
109 /// Help message bound to [`crate::parser::Args::lister_uri`]
110 /// field (i.e. lister uri option).
111 pub const LISTER_URI: &str = "The template lister uri";
112
113 /// Help message bound to [`crate::parser::Args::check_template_names`]
114 /// field (i.e. check option).
115 pub const CHECK: &str = "Enable robust template names check";
116
117 /// Help message bound to [`crate::parser::Args::timeout`]
118 /// field (i.e. timeout option).
119 pub const TIMEOUT: &str =
120 "The template generation and listing service calls timeout";
121
122 /// Help message bound to [`crate::parser::Args::timeout_unit`]
123 /// field (i.e. timeout unit option).
124 pub const TIMEOUT_UNIT: &str = "The timeout unit";
125}
126
127pub mod cli_options {
128 //! Constants for short and long cli options specifier.
129
130 use crate::helper::CliOptionName;
131
132 /// Short and long specifier for author option.
133 ///
134 /// **Value**: `-a --author`
135 pub const AUTHOR: CliOptionName = CliOptionName {
136 short: 'a',
137 long: "author",
138 };
139
140 /// Short and long specifier for server url option.
141 ///
142 /// **Value**: `-s --server-url`
143 pub const SERVER_URL: CliOptionName = CliOptionName {
144 short: 's',
145 long: "server-url",
146 };
147
148 /// Short and long specifier for help option.
149 ///
150 /// **Value**: `-h --help`
151 pub const HELP: CliOptionName = CliOptionName {
152 short: 'h',
153 long: "help",
154 };
155
156 /// Short and long specifier for version option.
157 ///
158 /// **Value**: `-V --version`
159 pub const VERSION: CliOptionName = CliOptionName {
160 short: 'V',
161 long: "version",
162 };
163
164 /// Short and long specifier for generator uri option.
165 ///
166 /// **Value**: `-g --generator-uri`
167 pub const GENERATOR_URI: CliOptionName = CliOptionName {
168 short: 'g',
169 long: "generator-uri",
170 };
171
172 /// Short and long specifier for template list option.
173 ///
174 /// **Value**: `-l --list`
175 pub const LIST: CliOptionName = CliOptionName {
176 short: 'l',
177 long: "list",
178 };
179
180 /// Short and long specifier for lister uri option.
181 ///
182 /// **Value**: `-i --lister-uri`
183 pub const LISTER_URI: CliOptionName = CliOptionName {
184 short: 'i',
185 long: "lister-uri",
186 };
187
188 /// Short and long specifier for check option.
189 ///
190 /// **Value**: `-c --check`
191 pub const CHECK: CliOptionName = CliOptionName {
192 short: 'c',
193 long: "check",
194 };
195
196 /// Short and long specifier for timeout option.
197 ///
198 /// **Value**: `-t --timeout`
199 pub const TIMEOUT: CliOptionName = CliOptionName {
200 short: 't',
201 long: "timeout",
202 };
203
204 /// Short and long specifier for timeout option.
205 ///
206 /// **Value**: `-u --timeout-unit`
207 pub const TIMEOUT_UNIT: CliOptionName = CliOptionName {
208 short: 'u',
209 long: "timeout-unit",
210 };
211}
212
213pub mod parser_infos {
214 //! Constants for general parser infos.
215
216 /// About text to be displayed when requesting help.
217 pub const ABOUT: &str = "Generate templates for .gitignore files";
218}
219
220pub mod exit_status {
221 //! Constants for script exit status code.
222
223 /// Exit status code for successful script execution.
224 pub const SUCCESS: i32 = 0;
225
226 /// Exit status code for generic script error.
227 pub const GENERIC: i32 = 2;
228
229 /// Exit status code for HTTP body parsing error.
230 pub const BODY_PARSING_ISSUE: i32 = 3;
231
232 /// Exit status code for any error from HTTP client itself.
233 pub const HTTP_CLIENT_ERROR: i32 = 4;
234}
235
236pub mod template_manager {
237 //! Constants for gitignore template manager service.
238
239 use crate::parser::TimeoutUnit;
240
241 /// Env variable name pointing to local template directory
242 pub const HOME_ENV_VAR: &str = "GITIGNORE_TEMPLATE_GENERATOR_HOME";
243
244 /// Default local template directory
245 pub const DEFAULT_HOME: &str = ".gitignore_template_generator";
246
247 /// Template manager service base URL.
248 pub const BASE_URL: &str = "https://www.toptal.com";
249
250 /// Template generator service URI.
251 ///
252 /// Used in conjunction with [`BASE_URL`] to build full URL and make
253 /// API call.
254 pub const GENERATOR_URI: &str = "/developers/gitignore/api";
255
256 /// Template lister service URI.
257 ///
258 /// Used in conjunction with [`BASE_URL`] to build full URL and make
259 /// API call.
260 pub const LISTER_URI: &str = "/developers/gitignore/api/list";
261
262 /// Timeout in seconds for HTTP calls to generator/lister service (str version).
263 pub const TIMEOUT: &str = "5";
264
265 /// Timeout in milliseconds for HTTP calls to generator/lister service (str version).
266 pub const TIMEOUT_MILLISECOND: &str = "5000";
267
268 /// Timeout in seconds for HTTP calls to generator/lister service (integer version).
269 pub const TIMEOUT_INT: u64 = 5;
270
271 /// Timeout milliseconds for HTTP calls to generator/lister service (integer version).
272 pub const TIMEOUT_MILLISECOND_INT: u64 = 5000;
273
274 /// Second timeout unit (str version).
275 pub const TIMEOUT_UNIT: &str = "second";
276
277 /// Millisecond timeout unit (str version).
278 pub const TIMEOUT_MILLISECOND_UNIT: &str = "millisecond";
279
280 /// Second timeout unit (enum version).
281 ///
282 /// `value` - TimeoutUnit::SECOND
283 pub const TIMEOUT_UNIT_ENUM: TimeoutUnit = TimeoutUnit::SECOND;
284}
285
286pub mod path {
287 //! Constants for file or directory path.
288
289 /// Path to directory containing test output expectations.
290 pub const TEST_EXPECTATIONS: &str = "tests/expected";
291
292 /// Path to directory containing test resources.
293 pub const TEST_RESOURCES: &str = "tests/resources";
294}