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