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
109pub mod cli_options {
110    //! Constants for short and long cli options specifier.
111
112    use crate::helper::CliOptionName;
113
114    /// Short and long specifier for author option.
115    ///
116    /// **Value**: `-a --author`
117    pub const AUTHOR: CliOptionName = CliOptionName {
118        short: 'a',
119        long: "author",
120    };
121
122    /// Short and long specifier for server url option.
123    ///
124    /// **Value**: `-s --server-url`
125    pub const SERVER_URL: CliOptionName = CliOptionName {
126        short: 's',
127        long: "server-url",
128    };
129
130    /// Short and long specifier for help option.
131    ///
132    /// **Value**: `-h --help`
133    pub const HELP: CliOptionName = CliOptionName {
134        short: 'h',
135        long: "help",
136    };
137
138    /// Short and long specifier for version option.
139    ///
140    /// **Value**: `-V --version`
141    pub const VERSION: CliOptionName = CliOptionName {
142        short: 'V',
143        long: "version",
144    };
145
146    /// Short and long specifier for generator uri option.
147    ///
148    /// **Value**: `-g --generator-uri`
149    pub const GENERATOR_URI: CliOptionName = CliOptionName {
150        short: 'g',
151        long: "generator-uri",
152    };
153
154    /// Short and long specifier for template list option.
155    ///
156    /// **Value**: `-l --list`
157    pub const LIST: CliOptionName = CliOptionName {
158        short: 'l',
159        long: "list",
160    };
161
162    /// Short and long specifier for lister uri option.
163    ///
164    /// **Value**: `-i --lister-uri`
165    pub const LISTER_URI: CliOptionName = CliOptionName {
166        short: 'i',
167        long: "lister-uri",
168    };
169
170    /// Short and long specifier for check option.
171    ///
172    /// **Value**: `-c --check`
173    pub const CHECK: CliOptionName = CliOptionName {
174        short: 'c',
175        long: "check",
176    };
177
178    /// Short and long specifier for timeout option.
179    ///
180    /// **Value**: `-t --timeout`
181    pub const TIMEOUT: CliOptionName = CliOptionName {
182        short: 't',
183        long: "timeout",
184    };
185}
186
187pub mod parser_infos {
188    //! Constants for general parser infos.
189
190    /// About text to be displayed when requesting help.
191    pub const ABOUT: &str = "Generate templates for .gitignore files";
192}
193
194pub mod exit_status {
195    //! Constants for script exit status code.
196
197    /// Exit status code for successful script execution.
198    pub const SUCCESS: i32 = 0;
199
200    /// Exit status code for generic script error.
201    pub const GENERIC: i32 = 2;
202
203    /// Exit status code for HTTP body parsing error.
204    pub const BODY_PARSING_ISSUE: i32 = 3;
205
206    /// Exit status code for any error from HTTP client itself.
207    pub const HTTP_CLIENT_ERROR: i32 = 4;
208}
209
210pub mod template_manager {
211    //! Constants for gitignore template manager service.
212
213    /// Template manager service base URL.
214    pub const BASE_URL: &str = "https://www.toptal.com";
215
216    /// Template generator service URI.
217    ///
218    /// Used in conjunction with [`BASE_URL`] to build full URL and make
219    /// API call.
220    pub const GENERATOR_URI: &str = "/developers/gitignore/api";
221
222    /// Template lister service URI.
223    ///
224    /// Used in conjunction with [`BASE_URL`] to build full URL and make
225    /// API call.
226    pub const LISTER_URI: &str = "/developers/gitignore/api/list";
227
228    /// Timeout for HTTP calls to generator/lister service.
229    pub const TIMEOUT: &str = "5";
230}
231
232pub mod path {
233    //! Constants for file or directory path.
234
235    /// Path to directory containing test output expectations.
236    pub const TEST_EXPECTATIONS: &str = "tests/expected";
237}