Boost Program Options Optional Value (request for implicit_value() behaviour change to allow space)
Description of the real problem: - let "-b" be the name of the option - it disables, if not present in command line, the general app logging - it enables, if present in command line, the general app logging in a default chosen logfile - it enables, if present in command line with a string argument, the general app logging into the file specified as string argument Usage example:
program_name (no logging) program_name -b (logging enabled; goes to logfile.log) program_name -b "C:\otherlogfile.log" (logs where specified)
So far I found a solution based on implicit_value() behaviour, with "-b" of type string, but my main problem is that in this case I am forced to enter the value to be adjacent to "-b" (e.g. -b"C:\otherlogfile.log"). The desired form would be the one with a space between, in order to maintain our backward compatibility of scripts (e.g: -b "C:\otherlogfile.log"). Can you help me with a good solution? (Even solutions that crack into the source of boost program options library are appreciated.) Thank you for your time. -- Kind regards, Andrei LIHU -------------------- softNRG C++ Software Developer +40742545392
On Wed, 08 Oct 2008 11:23:29 +0200, Andrei LIHU
[...]So far I found a solution based on implicit_value() behaviour, with "-b" of type string, but my main problem is that in this case I am forced to enter the value to be adjacent to "-b" (e.g. -b"C:\otherlogfile.log"). The desired form would be the one with a space between, in order to maintain our backward compatibility of scripts (e.g: -b "C:\otherlogfile.log").
If -b is a short option I would have thought that command_line_style::short_allow_next does what you want? Boris
Well, I thought so, but I tested that , and it doesn't do that. Here
are my styles:
po::command_line_style::style_t pstyle = po::command_line_style::style_t(
po::command_line_style::short_allow_next |
po::command_line_style::allow_dash_for_short |
po::command_line_style::allow_long |
po::command_line_style::allow_short |
po::command_line_style::long_allow_next |
po::command_line_style::case_insensitive |
po::command_line_style::allow_long_disguise );
// store the values in the variables' map
po::store(po::basic_command_line_parser<TCHAR>(args).style(pstyle).options(m_cmdlineOptions).allow_unregistered().run(),
m_vm);
po::notify(m_vm);
2008/10/8 Boris
On Wed, 08 Oct 2008 11:23:29 +0200, Andrei LIHU
wrote: [...]So far I found a solution based on implicit_value() behaviour, with "-b" of type string, but my main problem is that in this case I am forced to enter the value to be adjacent to "-b" (e.g. -b"C:\otherlogfile.log"). The desired form would be the one with a space between, in order to maintain our backward compatibility of scripts (e.g: -b "C:\otherlogfile.log").
If -b is a short option I would have thought that command_line_style::short_allow_next does what you want?
Boris
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Kind regards, Andrei LIHU -------------------- Soft NRG C++ Software Developer +40742545392
participants (2)
-
Andrei LIHU
-
Boris