problems with program_opsitons::parse_environment can't figure out how to do what I want.
variables_map vm_env; store(parse_environment(desc, "HOME"), vm_env); notify(vm_env); if(vm_env.count("HOME")) { path rcfile = ".koramarc"; path home; home = vm_env["HOME"].as<path>(); path tmp = home / rcfile; cout << "check" << endl; // just a retarted test to see if we're actually reaching the end of this... } -- Caleb Cushing http://xenoterracide.blogspot.com
On Wed, Sep 30, 2009 at 9:04 PM, Caleb Cushing
variables_map vm_env; store(parse_environment(desc, "HOME"), vm_env); notify(vm_env);
if(vm_env.count("HOME")) { path rcfile = ".koramarc"; path home; home = vm_env["HOME"].as<path>(); path tmp = home / rcfile; cout << "check" << endl; // just a retarted test to see if we're actually reaching the end of this... }
whoops... my code never enters the if statement and I'm not sure why. I'm still working on the best way to get the HOME variable from the env so I can more correctly reference ~/.koramarc. I need however to combine HOME with the actual rcfile name. and then I need to pass it to parse_config_file... but everything I've tried I just keep getting stumped... any help would really be appreciated, I've been trying various things for 3-ish days now. -- Caleb Cushing http://xenoterracide.blogspot.com
-----
To: boost-users@lists.boost.org From: Caleb Cushing
Date: 09/30/2009 09:07PM Subject: Re: [Boost-users] problems with program_opsitons::parse_environment can't figure out how to do what I want. On Wed, Sep 30, 2009 at 9:04 PM, Caleb Cushing
wrote: variables_map vm_env; store(parse_environment(desc, "HOME"), vm_env); notify(vm_env);
if(vm_env.count("HOME")) { path rcfile = ".koramarc"; path home; home = vm_env["HOME"].as<path>(); path tmp = home / rcfile; cout << "check" << endl; // just a retarted test to see if we're actually reaching the end of this... }
whoops... my code never enters the if statement and I'm not sure why.
I've never used parse_environment, but looking at the docs http://www.boost.org/doc/libs/1_40_0/doc/html/boost/program_options/parse_en..., this sounds like the problem: "Takes all environment variables which start with 'prefix'. The option name is obtained from variable name by removing the prefix and converting the remaining string into lower case." So, the HOME environmental is getting stored in the variable map under an empty key, if at all. I'm not sure how to fix it though. Maybe something like using "HOM" as the string for parse environment and "e" for the option name. Or you can use the other form of parse_environment that takes a function that maps variable names to option names. http://www.boost.org/doc/libs/1_40_0/doc/html/boost/program_options/parse_en... -- Anthony Foglia Princeton Consultants (609) 987-8787 x233
So, the HOME environmental is getting stored in the variable map under an empty key, if at all.
I'm not sure how to fix it though. Maybe something like using "HOM" as the string for parse environment and "e" for the option name. Or you can use the other form of parse_environment that takes a function that maps variable names to option names. http://www.boost.org/doc/libs/1_40_0/doc/html/boost/program_options/parse_en...
oh.... I misread the docs... I didn't realized it used the non prefix for the option name. guess I'll have to use getenv then since using HOM and e would be a horrible coding style. It's obvious this wasn't designed to use existing env variables. -- Caleb Cushing http://xenoterracide.blogspot.com
participants (2)
-
AFoglia@princeton.com
-
Caleb Cushing