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