I'm working on a command line tool that can read options from:
- The command line arguments
- An optional configuration file
I used Boost Program Options to read those options and it works mostly fine.
My code is like so:
namespace po = boost::program_options;
namespace fs = boost::filesystem;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, options), vm);
po::store(po::parse_config_file(ifs, options, true), vm);
po::notify(vm);
However, some of these options are file path and I'd like those to be relative to the origin of the option. Here is an example of what I mean:
Let's say my tool is located in: /usr/local/bin
mytool --foo.path ../config/assets/toto.txt
After parsing, the foo.path
option should be an absolute path to /usr/local/config/assets/toto.txt
.
Now if I specify foo.path
in a configuration file, located at /usr/local/config/myconf.cfg
like so:
foo.path=assets/toto.txt
I'd like the path to be relative to the configuration file (not the execution path) and that the resulting absolute path be the same as before.
Is there a way in Boost Program Options for knowing where the value of an option came from so I could adjust the path when transforming relative paths to absolute ones ?