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