JayBeams
0.1
Another project to have fun coding.
|
Compute the directories where a configuration file can be found. More...
#include <config_files_location.hpp>
Public Member Functions | |
config_files_locations (boost::filesystem::path const &argv0, char const *program_root_variable, getenv_functor getenv) | |
Constructor. More... | |
config_files_locations (boost::filesystem::path const &argv0, getenv_functor getenv) | |
Constructor. More... | |
boost::filesystem::path | find_configuration_file (std::string const &filename, validator_functor validator) const |
Find a configuration file in the computed search path. More... | |
boost::filesystem::path | find_configuration_file (std::string const &filename) const |
Find a configuration file in the computed search path. More... | |
config_files_locations (boost::filesystem::path const &argv0, char const *program_root_variable) | |
Convenience constructors. More... | |
config_files_locations (boost::filesystem::path const &argv0) | |
config_files_locations (char const *argv0, char const *program_root_variable, getenv_functor getenv) | |
config_files_locations (char const *argv0, char const *program_root_variable) | |
config_files_locations (char const *argv0, getenv_functor getenv) | |
config_files_locations (char const *argv0) | |
![]() | |
std::vector< boost::filesystem::path > const & | search_path () const |
Additional Inherited Members | |
![]() | |
config_files_locations_base (boost::filesystem::path const &argv0, std::function< char const *(char const *)> getenv, char const *program_root_variable) | |
Constructor. More... | |
config_files_locations_base (boost::filesystem::path const &argv0, std::function< char const *(char const *)> getenv) | |
Constructor. More... | |
Compute the directories where a configuration file can be found.
JayBeams configuration files can be located in multiple places:
files are searched there if the variable is defined, otherwise
that environment variable is defined, otherwise
directory exists, otherwise,
This class implements the algorithms to (a) compute the valid list of directories for a given program, and (b) select which configuration file to load.
We use some template parameters for dependency injection, it is hard to test the interaction with the file system (and the environment variables) without them.
getenv_functor | the functor used to fetch the value of environment variables. This is used for dependency injection during testing. |
validator_functor | the functor used to validate if a given path is readable. This is used for dependency injection during testing. |
Definition at line 103 of file config_files_location.hpp.
|
inline |
Constructor.
Build the search path given the program path and the name of its preferred environment variable.
argv0 | the program path, typically argv[0] from main() |
program_root_variable | the name of the preferred environment variable for this program, i.e., its *_ROOT variable. |
getenv | the functor object to use |
Definition at line 116 of file config_files_location.hpp.
|
inline |
Constructor.
Build the search path given the program path. Used in programs that do not have a preferred *_ROOT environment variable.
argv0 | the program path, typically argv[0] from main() |
getenv | the functor object to use |
Definition at line 131 of file config_files_location.hpp.
|
inline |
Convenience constructors.
Apply common conversions and create functors as needed.
Definition at line 142 of file config_files_location.hpp.
|
inlineexplicit |
Definition at line 146 of file config_files_location.hpp.
|
inline |
Definition at line 149 of file config_files_location.hpp.
|
inline |
Definition at line 155 of file config_files_location.hpp.
|
inline |
Definition at line 160 of file config_files_location.hpp.
|
inlineexplicit |
Definition at line 163 of file config_files_location.hpp.
|
inline |
Find a configuration file in the computed search path.
filename | the basename of the configuration file. |
validator | the functor to use for validation |
std::runtime_error | if no suitable file was found. |
Definition at line 178 of file config_files_location.hpp.
|
inline |
Find a configuration file in the computed search path.
filename | the basename of the configuration file. |
std::runtime_error | if no suitable file was found. |
Definition at line 200 of file config_files_location.hpp.
References jb::bindir(), and jb::sysconfdir().