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
17
18#include <optional>
19#include <string>
20
21namespace shamcmdopt {
22
30 std::optional<std::string> getenv_str(const char *env_var);
31
39 std::optional<std::string_view> getenv_str_view(const char *env_var);
40
49 inline std::string getenv_str_default(const char *env_var, std::string default_val) {
50 auto val = getenv_str(env_var);
51 return val ? *val : default_val;
52 }
53
65 void register_env_var_doc(std::string env_var, std::string desc);
66
79 inline std::optional<std::string> getenv_str_register(const char *env_var, std::string desc) {
80 register_env_var_doc(env_var, desc);
81 return getenv_str(env_var);
82 }
83
97 inline std::string getenv_str_default_register(
98 const char *env_var, std::string default_val, std::string desc) {
99 register_env_var_doc(env_var, desc);
100 return getenv_str_default(env_var, default_val);
101 }
102
111 void print_help_env_var();
112
113} // 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:97
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:55
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:79
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:49
void register_env_var_doc(std::string env_var, std::string desc)
Register the documentation of an environment variable.
Definition env.cpp:43
std::optional< std::string_view > getenv_str_view(const char *env_var)
Get the content of the environment variable if it exist.
Definition env.cpp:32