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
69pub mod help_messages {
70 //! Constants for help messages to be displayed.
71
72 /// Help message bound to [`crate::parser::Args::template_names`]
73 /// field (i.e. positional args).
74 pub const TEMPLATE_NAMES: &str =
75 "A non-empty list of gitignore template names";
76
77 /// Help message bound to [`crate::parser::Args::show_author`]
78 /// field (i.e. author option).
79 pub const AUTHOR: &str = "Print author";
80
81 /// Help message bound to [`crate::parser::Args::server_url`]
82 /// field (i.e. server url option).
83 pub const SERVER_URL: &str = "The template manager url";
84
85 /// Help message bound to [`crate::parser::Args::show_help`]
86 /// field (i.e. help option).
87 pub const HELP: &str = "Print help";
88
89 /// Help message bound to [`crate::parser::Args::show_version`]
90 /// field (i.e. version option).
91 pub const VERSION: &str = "Print version";
92
93 /// Help message bound to [`crate::parser::Args::generator_uri`]
94 /// field (i.e. generator uri option).
95 pub const GENERATOR_URI: &str = "The template generator uri";
96
97 /// Help message bound to [`crate::parser::Args::show_list`]
98 /// field (i.e. list option).
99 pub const LIST: &str = "List available templates";
100
101 /// Help message bound to [`crate::parser::Args::lister_uri`]
102 /// field (i.e. lister uri option).
103 pub const LISTER_URI: &str = "The template lister uri";
104
105 /// Help message bound to [`crate::parser::Args::check_template_names`]
106 /// field (i.e. check option).
107 pub const CHECK: &str = "Enable robust template names check";
108
109 /// Help message bound to [`crate::parser::Args::timeout`]
110 /// field (i.e. timeout option).
111 pub const TIMEOUT: &str =
112 "The template generation and listing service calls timeout";
113
114 /// Help message bound to [`crate::parser::Args::timeout_unit`]
115 /// field (i.e. timeout unit option).
116 pub const TIMEOUT_UNIT: &str = "The timeout unit";
117}
118
119pub mod cli_options {
120 //! Constants for short and long cli options specifier.
121
122 use crate::helper::CliOptionName;
123
124 /// Short and long specifier for author option.
125 ///
126 /// **Value**: `-a --author`
127 pub const AUTHOR: CliOptionName = CliOptionName {
128 short: 'a',
129 long: "author",
130 };
131
132 /// Short and long specifier for server url option.
133 ///
134 /// **Value**: `-s --server-url`
135 pub const SERVER_URL: CliOptionName = CliOptionName {
136 short: 's',
137 long: "server-url",
138 };
139
140 /// Short and long specifier for help option.
141 ///
142 /// **Value**: `-h --help`
143 pub const HELP: CliOptionName = CliOptionName {
144 short: 'h',
145 long: "help",
146 };
147
148 /// Short and long specifier for version option.
149 ///
150 /// **Value**: `-V --version`
151 pub const VERSION: CliOptionName = CliOptionName {
152 short: 'V',
153 long: "version",
154 };
155
156 /// Short and long specifier for generator uri option.
157 ///
158 /// **Value**: `-g --generator-uri`
159 pub const GENERATOR_URI: CliOptionName = CliOptionName {
160 short: 'g',
161 long: "generator-uri",
162 };
163
164 /// Short and long specifier for template list option.
165 ///
166 /// **Value**: `-l --list`
167 pub const LIST: CliOptionName = CliOptionName {
168 short: 'l',
169 long: "list",
170 };
171
172 /// Short and long specifier for lister uri option.
173 ///
174 /// **Value**: `-i --lister-uri`
175 pub const LISTER_URI: CliOptionName = CliOptionName {
176 short: 'i',
177 long: "lister-uri",
178 };
179
180 /// Short and long specifier for check option.
181 ///
182 /// **Value**: `-c --check`
183 pub const CHECK: CliOptionName = CliOptionName {
184 short: 'c',
185 long: "check",
186 };
187
188 /// Short and long specifier for timeout option.
189 ///
190 /// **Value**: `-t --timeout`
191 pub const TIMEOUT: CliOptionName = CliOptionName {
192 short: 't',
193 long: "timeout",
194 };
195
196 /// Short and long specifier for timeout option.
197 ///
198 /// **Value**: `-u --timeout-unit`
199 pub const TIMEOUT_UNIT: CliOptionName = CliOptionName {
200 short: 'u',
201 long: "timeout-unit",
202 };
203}
204
205pub mod parser_infos {
206 //! Constants for general parser infos.
207
208 /// About text to be displayed when requesting help.
209 pub const ABOUT: &str = "Generate templates for .gitignore files";
210}
211
212pub mod exit_status {
213 //! Constants for script exit status code.
214
215 /// Exit status code for successful script execution.
216 pub const SUCCESS: i32 = 0;
217
218 /// Exit status code for generic script error.
219 pub const GENERIC: i32 = 2;
220
221 /// Exit status code for HTTP body parsing error.
222 pub const BODY_PARSING_ISSUE: i32 = 3;
223
224 /// Exit status code for any error from HTTP client itself.
225 pub const HTTP_CLIENT_ERROR: i32 = 4;
226}
227
228pub mod template_manager {
229 //! Constants for gitignore template manager service.
230
231 use crate::parser::TimeoutUnit;
232
233 /// Template manager service base URL.
234 pub const BASE_URL: &str = "https://www.toptal.com";
235
236 /// Template generator service URI.
237 ///
238 /// Used in conjunction with [`BASE_URL`] to build full URL and make
239 /// API call.
240 pub const GENERATOR_URI: &str = "/developers/gitignore/api";
241
242 /// Template lister service URI.
243 ///
244 /// Used in conjunction with [`BASE_URL`] to build full URL and make
245 /// API call.
246 pub const LISTER_URI: &str = "/developers/gitignore/api/list";
247
248 /// Timeout in seconds for HTTP calls to generator/lister service (str version).
249 pub const TIMEOUT: &str = "5";
250
251 /// Timeout in milliseconds for HTTP calls to generator/lister service (str version).
252 pub const TIMEOUT_MILLISECOND: &str = "5000";
253
254 /// Timeout in seconds for HTTP calls to generator/lister service (integer version).
255 pub const TIMEOUT_INT: u64 = 5;
256
257 /// Timeout milliseconds for HTTP calls to generator/lister service (integer version).
258 pub const TIMEOUT_MILLISECOND_INT: u64 = 5000;
259
260 /// Second timeout unit (str version).
261 pub const TIMEOUT_UNIT: &str = "second";
262
263 /// Millisecond timeout unit (str version).
264 pub const TIMEOUT_MILLISECOND_UNIT: &str = "millisecond";
265
266 /// Second timeout unit (enum version).
267 ///
268 /// `value` - TimeoutUnit::SECOND
269 pub const TIMEOUT_UNIT_ENUM: TimeoutUnit = TimeoutUnit::SECOND;
270}
271
272pub mod path {
273 //! Constants for file or directory path.
274
275 /// Path to directory containing test output expectations.
276 pub const TEST_EXPECTATIONS: &str = "tests/expected";
277}