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    pub const INEXISTENT_TEMPLATE_NAMES: &str = "Following template names are not supported: {templates}. For the list of available template names, try '--list'.";
51}
52
53pub mod help_messages {
54    //! Constants for help messages to be displayed.
55
56    /// Help message bound to [`crate::parser::Args::template_names`]
57    /// field (i.e. positional args).
58    pub const TEMPLATE_NAMES: &str =
59        "A non-empty list of gitignore template names";
60
61    /// Help message bound to [`crate::parser::Args::show_author`]
62    /// field (i.e. author option).
63    pub const AUTHOR: &str = "Print author";
64
65    /// Help message bound to [`crate::parser::Args::server_url`]
66    /// field (i.e. server url option).
67    pub const SERVER_URL: &str = "The template manager url";
68
69    /// Help message bound to [`crate::parser::Args::show_help`]
70    /// field (i.e. help option).
71    pub const HELP: &str = "Print help";
72
73    /// Help message bound to [`crate::parser::Args::show_version`]
74    /// field (i.e. version option).
75    pub const VERSION: &str = "Print version";
76
77    /// Help message bound to [`crate::parser::Args::generator_uri`]
78    /// field (i.e. generator uri option).
79    pub const GENERATOR_URI: &str = "The template generator uri";
80
81    /// Help message bound to [`crate::parser::Args::show_list`]
82    /// field (i.e. list option).
83    pub const LIST: &str = "List available templates";
84
85    /// Help message bound to [`crate::parser::Args::lister_uri`]
86    /// field (i.e. lister uri option).
87    pub const LISTER_URI: &str = "The template lister uri";
88
89    /// Help message bound to [`crate::parser::Args::check_template_names`]
90    /// field (i.e. check option).
91    pub const CHECK: &str = "Enable robust template names check";
92}
93
94pub mod cli_options {
95    //! Constants for short and long cli options specifier.
96
97    use crate::helper::CliOptionName;
98
99    /// Short and long specifier for author option.
100    ///
101    /// **Value**: `-a --author`
102    pub const AUTHOR: CliOptionName = CliOptionName {
103        short: 'a',
104        long: "author",
105    };
106
107    /// Short and long specifier for server url option.
108    ///
109    /// **Value**: `-s --server-url`
110    pub const SERVER_URL: CliOptionName = CliOptionName {
111        short: 's',
112        long: "server-url",
113    };
114
115    /// Short and long specifier for help option.
116    ///
117    /// **Value**: `-h --help`
118    pub const HELP: CliOptionName = CliOptionName {
119        short: 'h',
120        long: "help",
121    };
122
123    /// Short and long specifier for version option.
124    ///
125    /// **Value**: `-V --version`
126    pub const VERSION: CliOptionName = CliOptionName {
127        short: 'V',
128        long: "version",
129    };
130
131    /// Short and long specifier for generator uri option.
132    ///
133    /// **Value**: `-g --generator-uri`
134    pub const GENERATOR_URI: CliOptionName = CliOptionName {
135        short: 'g',
136        long: "generator-uri",
137    };
138
139    /// Short and long specifier for template list option.
140    ///
141    /// **Value**: `-l --list`
142    pub const LIST: CliOptionName = CliOptionName {
143        short: 'l',
144        long: "list",
145    };
146
147    /// Short and long specifier for lister uri option.
148    ///
149    /// **Value**: `-i --lister-uri`
150    pub const LISTER_URI: CliOptionName = CliOptionName {
151        short: 'i',
152        long: "lister-uri",
153    };
154
155    /// Short and long specifier for check option.
156    ///
157    /// **Value**: `-c --check`
158    pub const CHECK: CliOptionName = CliOptionName {
159        short: 'c',
160        long: "check",
161    };
162}
163
164pub mod parser_infos {
165    //! Constants for general parser infos.
166
167    /// About text to be displayed when requesting help.
168    pub const ABOUT: &str = "Generate templates for .gitignore files";
169}
170
171pub mod exit_status {
172    //! Constants for script exit status code.
173
174    /// Exit status code for successful script execution.
175    pub const SUCCESS: i32 = 0;
176
177    /// Exit status code for generic script error.
178    pub const GENERIC: i32 = 2;
179
180    /// Exit status code for HTTP body parsing error.
181    pub const BODY_PARSING_ISSUE: i32 = 3;
182}
183
184pub mod template_manager {
185    //! Constants for gitignore template manager service.
186
187    /// Template manager service base URL.
188    pub const BASE_URL: &str = "https://www.toptal.com";
189
190    /// Template generator service URI.
191    ///
192    /// Used in conjunction with [`BASE_URL`] to build full URL and make
193    /// API call.
194    pub const GENERATOR_URI: &str = "/developers/gitignore/api";
195
196    /// Template lister service URI.
197    ///
198    /// Used in conjunction with [`BASE_URL`] to build full URL and make
199    /// API call.
200    pub const LISTER_URI: &str = "/developers/gitignore/api/list";
201}
202
203pub mod path {
204    //! Constants for file or directory path.
205
206    /// Path to directory containing test output expectations.
207    pub const TEST_EXPECTATIONS: &str = "tests/expected";
208}