![]() |
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::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_a_tty () |
| Test if current terminal is a tty. | |
| u32 | get_tty_columns () |
| Get the number of columns of the current terminal. | |
| u32 | get_tty_lines () |
| Get the number of lines of the current terminal. | |
| void | set_tty_columns (u32 columns) |
| Set the forced width of the terminal. | |
| void | reset_tty_columns () |
| Reset the forced width of the terminal. | |
| 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_colors () |
| Detect if the current process should use colored output or not. | |
| void | process_tty () |
| Process the SHAMTTYCOL environment variable to set the number of columns for the terminal. | |
| std::pair< u32, u32 > | get_tty_dim () |
| Get the number of columns and lines of the current terminal. | |
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 | |
| u32 | tty_forced_width = 0 |
namespace for cli utilities
|
protected |
Check if all argument passed to shamrock where registered otherwise throw.
Definition at line 95 of file cmdopt.cpp.
Here is the call graph for this function:
|
protected |
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 197 of file cmdopt.cpp.
| char ** shamcmdopt::get_argv | ( | ) |
Get the command line arguments.
Definition at line 203 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.
Here is the call graph for this function:| u32 shamcmdopt::get_tty_columns | ( | ) |
Get the number of columns of the current terminal.
If forced width is set (by set_tty_columns), this function returns the forced width. If the current terminal is not a tty, the function returns 100.
Definition at line 81 of file tty.cpp.
Here is the call graph for this function:Get the number of columns and lines of the current terminal.
If forced width is set (by set_tty_columns), this function returns the forced width. If the current terminal is not a tty, the function returns {10, 100}.
Definition at line 53 of file tty.cpp.
Here is the call graph for this function:| u32 shamcmdopt::get_tty_lines | ( | ) |
| 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 40 of file env.hpp.
Here is the call graph for this function:
|
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 88 of file env.hpp.
Here is the call graph for this function:
|
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 70 of file env.hpp.
Here is the call graph for this function:| 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.
Here is the call graph for this function:| 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 183 of file cmdopt.cpp.
Here is the call graph for this function:| bool shamcmdopt::is_a_tty | ( | ) |
| 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 280 of file cmdopt.cpp.
Here is the call graph for this function:
|
protected |
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 231 of file cmdopt.cpp.
Here is the call graph for this function:| void shamcmdopt::print_help | ( | ) |
Print the help message.
Definition at line 210 of file cmdopt.cpp.
Here is the call graph for this function:| 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 47 of file env.cpp.
Here is the call graph for this function:| void shamcmdopt::process_cmdopt_generic_opts | ( | ) |
Process generic cli and env variables options.
Definition at line 162 of file generic_opts.cpp.
Here is the call graph for this function:| void shamcmdopt::process_colors | ( | ) |
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 103 of file generic_opts.cpp.
Here is the call graph for this function:| void shamcmdopt::process_tty | ( | ) |
Process the SHAMTTYCOL environment variable to set the number of columns for the terminal.
If the variable is set, its value is parsed as an integer and used to set the terminal columns. If the value is less than the minimum size (10), it is set to the minimum size. If the value is not an integer or is out of range, an error message is printed.
Definition at line 141 of file generic_opts.cpp.
Here is the call graph for this function:| void shamcmdopt::register_cmdopt_generic_opts | ( | ) |
Register generic cli and env variables options.
Definition at line 76 of file generic_opts.cpp.
Here is the call graph for this function:| 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 35 of file env.cpp.
Here is the call graph for this function:| 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.
Here is the call graph for this function:
|
inline |
Reset the forced width of the terminal.
Calls set_tty_columns(0) to restore the default behavior of get_tty_columns().
Definition at line 67 of file tty.hpp.
Here is the call graph for this function:| void shamcmdopt::set_tty_columns | ( | u32 | columns | ) |
Set the forced width of the terminal.
By default, the function get_tty_columns() returns the number of columns of the current terminal. If this function is called with a non-zero value, get_tty_columns() will always return this value until set_tty_columns() is called again with a different value.
| columns | The width of the terminal. If zero, the default behavior of get_tty_columns() is restored. |
|
protected |
supplied argc from main
Definition at line 178 of file cmdopt.cpp.
|
protected |
Executable argument list (mapped from argv)
Definition at line 63 of file cmdopt.cpp.
|
protected |
supplied argv from main
Definition at line 181 of file cmdopt.cpp.
|
protected |
Error string to be printed in case of failure.
Definition at line 57 of file cmdopt.cpp.
|
protected |
Executable name.
Definition at line 62 of file cmdopt.cpp.
|
protected |
Has cmdopt init been called.
Definition at line 64 of file cmdopt.cpp.
|
protected |
Registered cli options.
Definition at line 74 of file cmdopt.cpp.