Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
env.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
18#include <optional>
19#include <string>
20
21namespace shamcmdopt {
22
30 std::optional<std::string> getenv_str(const char *env_var);
31
40 inline std::string getenv_str_default(const char *env_var, std::string default_val) {
41 auto val = getenv_str(env_var);
42 return val ? *val : default_val;
43 }
44
56 void register_env_var_doc(std::string env_var, std::string desc);
57
70 inline std::optional<std::string> getenv_str_register(const char *env_var, std::string desc) {
71 register_env_var_doc(env_var, desc);
72 return getenv_str(env_var);
73 }
74
88 inline std::string getenv_str_default_register(
89 const char *env_var, std::string default_val, std::string desc) {
90 register_env_var_doc(env_var, desc);
91 return getenv_str_default(env_var, default_val);
92 }
93
102 void print_help_env_var();
103
104} // namespace shamcmdopt
namespace for cli utilities
Definition ci_env.hpp:19
std::string getenv_str_default_register(const char *env_var, std::string default_val, std::string desc)
Get the content of the environment variable if it exist and register it documentation,...
Definition env.hpp:88
std::optional< std::string > getenv_str(const char *env_var)
Get the content of the environment variable if it exist.
Definition env.cpp:24
void print_help_env_var()
Print the documentation of the environment variables registered with register_env_var_doc()
Definition env.cpp:47
std::optional< std::string > getenv_str_register(const char *env_var, std::string desc)
Get the content of the environment variable if it exist and register it documentation.
Definition env.hpp:70
std::string getenv_str_default(const char *env_var, std::string default_val)
Get the content of the environment variable if it exist, otherwise return the default value.
Definition env.hpp:40
void register_env_var_doc(std::string env_var, std::string desc)
Register the documentation of an environment variable.
Definition env.cpp:35