![]() |
Shamrock 2025.10.0
Astrophysical Code
|
namespace for cli utilities More...
Classes | |
| struct | Opts |
| Struct for data related to an option. More... | |
Functions | |
| bool | is_ci_github_actions () |
| Check if the environment variable GITHUB_ACTIONS is set. | |
| bool | is_ci_travis () |
| Check if the environment variable TRAVIS is set. | |
| bool | is_ci_circle_ci () |
| Check if the environment variable CIRCLECI is set. | |
| bool | is_ci_gitlab_ci () |
| Check if the environment variable GITLAB_CI is set. | |
| int | get_argc () |
| Get the number of command line arguments. | |
| char ** | get_argv () |
| Get the command line arguments. | |
| void | register_opt (std::string name, std::optional< std::string > args, std::string description) |
| Register a command line option. | |
| void | init (int argc, char *argv[]) |
| Initialize the command line option parser. We also process generic options in this call (color detection typically). | |
| bool | has_option (const std::string_view &option_name) |
| Check if an option is present. | |
| std::string_view | get_option (const std::string_view &option_name) |
| Get the value of an option. | |
| void | print_help () |
| Print the help message. | |
| void | print_completion_zsh () |
| print zsh completion script to be sourced | |
| bool | is_help_mode () |
| Check if the help mode is enabled. | |
| void | register_cmdopt_generic_opts () |
| Register generic cli and env variables options. | |
| void | process_cmdopt_generic_opts () |
| Process generic cli and env variables options. | |
| std::optional< std::string > | getenv_str (const char *env_var) |
| Get the content of the environment variable if it exist. | |
| std::optional< std::string_view > | getenv_str_view (const char *env_var) |
| Get the content of the environment variable if it exist. | |
| 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. | |
| void | register_env_var_doc (std::string env_var, std::string desc) |
| Register the documentation of an environment variable. | |
| 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. | |
| 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, otherwise return the default value. | |
| void | print_help_env_var () |
| Print the documentation of the environment variables registered with register_env_var_doc(). | |
| bool | is_name_registered (const std::string_view &name) |
| Check if the option name is registered. | |
| void | check_args_registered () |
| Check if all argument passed to shamrock where registered otherwise throw. | |
| void | check_init () |
| Check if init has been performed otherwise throw. | |
| void | process_env_vars () |
| Detect if the current process should use colored output or not. | |
Variables | |
| auto | err_str |
| Error string to be printed in case of failure. | |
| std::string_view | executable_name |
| Executable name. | |
| std::vector< std::string_view > | args |
| Executable argument list (mapped from argv). | |
| bool | init_done |
| Has cmdopt init been called. | |
| std::vector< Opts > | registered_opts |
| Registered cli options. | |
| int | argc |
| supplied argc from main | |
| char ** | argv |
| supplied argv from main | |
namespace for cli utilities
| void shamcmdopt::check_args_registered | ( | ) |
Check if all argument passed to shamrock where registered otherwise throw.
Definition at line 95 of file cmdopt.cpp.
| void shamcmdopt::check_init | ( | ) |
Check if init has been performed otherwise throw.
Definition at line 123 of file cmdopt.cpp.
| int shamcmdopt::get_argc | ( | ) |
Get the number of command line arguments.
Definition at line 198 of file cmdopt.cpp.
| char ** shamcmdopt::get_argv | ( | ) |
Get the command line arguments.
Definition at line 204 of file cmdopt.cpp.
| std::string_view shamcmdopt::get_option | ( | const std::string_view & | option_name | ) |
Get the value of an option.
| option_name | The name of the option. |
Definition at line 146 of file cmdopt.cpp.
| std::optional< std::string > shamcmdopt::getenv_str | ( | const char * | env_var | ) |
|
inline |
Get the content of the environment variable if it exist, otherwise return the default value.
| env_var | the name of the env variable |
| default_val | the default value to return if the env variable does not exist |
Definition at line 49 of file env.hpp.
|
inline |
Get the content of the environment variable if it exist and register it documentation, otherwise return the default value.
This function is a shortcut for calling both getenv_str_default() and register_env_var_doc(). It is used to register the documentation of the environment variable and return its value if it exist, otherwise return the default value.
| env_var | the name of the env variable |
| default_val | the default value to return if the env variable does not exist |
| desc | the description of the environment variable |
Definition at line 97 of file env.hpp.
|
inline |
Get the content of the environment variable if it exist and register it documentation.
This function is a shortcut for calling both getenv_str() and register_env_var_doc(). It is used to register the documentation of the environment variable and return its value if it exist.
| env_var | the name of the env variable |
| desc | the description of the environment variable |
Definition at line 79 of file env.hpp.
| std::optional< std::string_view > shamcmdopt::getenv_str_view | ( | const char * | env_var | ) |
| bool shamcmdopt::has_option | ( | const std::string_view & | option_name | ) |
Check if an option is present.
| option_name | The name of the option. |
Definition at line 128 of file cmdopt.cpp.
| void shamcmdopt::init | ( | int | argc, |
| char * | argv[] ) |
Initialize the command line option parser. We also process generic options in this call (color detection typically).
| argc | The number of command line arguments. |
| argv | The command line arguments. |
Definition at line 184 of file cmdopt.cpp.
| bool shamcmdopt::is_ci_circle_ci | ( | ) |
Check if the environment variable CIRCLECI is set.
This is used to check if the code is run in a CircleCI job.
Definition at line 58 of file ci_env.cpp.
| bool shamcmdopt::is_ci_github_actions | ( | ) |
Check if the environment variable GITHUB_ACTIONS is set.
This is used to check if the code is run in a GitHub Actions CI job.
Definition at line 40 of file ci_env.cpp.
| bool shamcmdopt::is_ci_gitlab_ci | ( | ) |
Check if the environment variable GITLAB_CI is set.
This is used to check if the code is run in a GitLab CI job.
Definition at line 67 of file ci_env.cpp.
| bool shamcmdopt::is_ci_travis | ( | ) |
Check if the environment variable TRAVIS is set.
This is used to check if the code is run in a Travis CI job.
Definition at line 49 of file ci_env.cpp.
| bool shamcmdopt::is_help_mode | ( | ) |
Check if the help mode is enabled.
Definition at line 281 of file cmdopt.cpp.
| bool shamcmdopt::is_name_registered | ( | const std::string_view & | name | ) |
Check if the option name is registered.
| name | the option name (including dashes) |
Definition at line 83 of file cmdopt.cpp.
| void shamcmdopt::print_completion_zsh | ( | ) |
print zsh completion script to be sourced
Definition at line 232 of file cmdopt.cpp.
| void shamcmdopt::print_help | ( | ) |
Print the help message.
Definition at line 211 of file cmdopt.cpp.
| void shamcmdopt::print_help_env_var | ( | ) |
Print the documentation of the environment variables registered with register_env_var_doc().
This function is used to print the documentation of the environment variables registered with register_env_var_doc(). It will print the name, the description and the value of each registered environment variable.
Definition at line 55 of file env.cpp.
| void shamcmdopt::process_cmdopt_generic_opts | ( | ) |
Process generic cli and env variables options.
In order the priority to enable a feature is CLI arg > ENV > detection
Definition at line 105 of file generic_opts.cpp.
| void shamcmdopt::process_env_vars | ( | ) |
Detect if the current process should use colored output or not.
Colors are disabled by the cli flag --nocolor or env variable NO_COLOR Colors are enabled by the cli flag --color or env variable CLICOLOR_FORCE If no options are set we enable colors if in tty mode and if the terminal support colored output
Definition at line 71 of file generic_opts.cpp.
| void shamcmdopt::register_cmdopt_generic_opts | ( | ) |
Register generic cli and env variables options.
Definition at line 44 of file generic_opts.cpp.
| void shamcmdopt::register_env_var_doc | ( | std::string | env_var, |
| std::string | desc ) |
Register the documentation of an environment variable.
This function is used to register the documentation of an environment variable. The documentation will be printed in the help message.
| std::invalid_argument | if the environment variable is already registered |
| env_var | the name of the environment variable |
| desc | the description of the environment variable |
Definition at line 43 of file env.cpp.
| void shamcmdopt::register_opt | ( | std::string | name, |
| std::optional< std::string > | args, | ||
| std::string | description ) |
Register a command line option.
| name | The name of the option. |
| args | The arguments of the option. If the option takes no argument, pass std::nullopt. |
| description | The description of the option. |
Definition at line 165 of file cmdopt.cpp.
| int shamcmdopt::argc |
supplied argc from main
Definition at line 179 of file cmdopt.cpp.
| std::vector<std::string_view> shamcmdopt::args |
Executable argument list (mapped from argv).
Definition at line 63 of file cmdopt.cpp.
| char** shamcmdopt::argv |
supplied argv from main
Definition at line 182 of file cmdopt.cpp.
| auto shamcmdopt::err_str |
Error string to be printed in case of failure.
Definition at line 57 of file cmdopt.cpp.
| std::string_view shamcmdopt::executable_name |
Executable name.
Definition at line 62 of file cmdopt.cpp.
| bool shamcmdopt::init_done |
Has cmdopt init been called.
Definition at line 64 of file cmdopt.cpp.
| std::vector<Opts> shamcmdopt::registered_opts |
Registered cli options.
Definition at line 74 of file cmdopt.cpp.