Line | Count | Source |
1 | | #ifndef NANOMMO_PROTOCOL_SETTINGS_H_ |
2 | | #define NANOMMO_PROTOCOL_SETTINGS_H_ |
3 | | |
4 | | #include <cstdlib> |
5 | | #include <string> |
6 | | |
7 | | namespace nanommo { |
8 | | |
9 | 0 | inline std::string Setting(const char* name, const std::string& fallback) { |
10 | 0 | const char* value = std::getenv(name); |
11 | 0 | return value != nullptr ? value : fallback; |
12 | 0 | } |
13 | | |
14 | | /// A file or a folder a program reads: the setting called name, if it's set, |
15 | | /// or else path in the repository the program was built from, so it runs from |
16 | | /// any folder. Where the repository hasn't got it, as in a Docker image, which |
17 | | /// leaves the repository behind, path is from the folder it runs in. A path in |
18 | | /// neither comes back from the repository, where an error should send you. |
19 | | std::string FileSetting(const char* name, const std::string& path); |
20 | | |
21 | | } // namespace nanommo |
22 | | |
23 | | #endif // NANOMMO_PROTOCOL_SETTINGS_H_ |