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