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
80pub mod cli_options {
81    //! Constants for short and long cli options specifier.
82
83    use crate::helper::CliOptionName;
84
85    /// Short and long specifier for author option.
86    ///
87    /// **Value**: `-a --author`
88    pub const AUTHOR: CliOptionName = CliOptionName {
89        short: 'a',
90        long: "author",
91    };
92
93    /// Short and long specifier for server url option.
94    ///
95    /// **Value**: `-s --server-url`
96    pub const SERVER_URL: CliOptionName = CliOptionName {
97        short: 's',
98        long: "server-url",
99    };
100
101    /// Short and long specifier for help option.
102    ///
103    /// **Value**: `-h --help`
104    pub const HELP: CliOptionName = CliOptionName {
105        short: 'h',
106        long: "help",
107    };
108
109    /// Short and long specifier for version option.
110    ///
111    /// **Value**: `-V --version`
112    pub const VERSION: CliOptionName = CliOptionName {
113        short: 'V',
114        long: "version",
115    };
116
117    /// Short and long specifier for endpoint uri option.
118    ///
119    /// **Value**: `-e --endpoint-uri`
120    pub const ENDPOINT_URI: CliOptionName = CliOptionName {
121        short: 'e',
122        long: "endpoint-uri",
123    };
124}
125
126pub mod parser_infos {
127    //! Constants for general parser infos.
128
129    /// About text to be displayed when requesting help.
130    pub const ABOUT: &str = "Generate templates for .gitignore files";
131}
132
133pub mod exit_status {
134    //! Constants for script exit status code.
135
136    /// Exit status code for successful script execution.
137    pub const SUCCESS: i32 = 0;
138
139    /// Exit status code for generic script error.
140    pub const GENERIC: i32 = 2;
141
142    /// Exit status code for HTTP body parsing error.
143    pub const BODY_PARSING_ISSUE: i32 = 3;
144}
145
146pub mod template_generator {
147    //! Constants for template generator service.
148
149    /// Template generator service base URL.
150    pub const BASE_URL: &str = "https://www.toptal.com";
151
152    /// Template generator service URI.
153    ///
154    /// Used in conjunction with [`BASE_URL`] to build full URL and make
155    /// API call.
156    pub const URI: &str = "/developers/gitignore/api";
157}
158
159pub mod path {
160    //! Constants for file or directory path.
161
162    /// Path to directory containing test output expectations.
163    pub const TEST_EXPECTATIONS: &str = "tests/expected";
164}