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