Hello, Is there a mechanism in boost::program_options for supporting optional arguments? If not, is there a suggested program_options-based alternative? This question was posed by someone else about a year ago, but did not get a response. Here is the quote: BEGIN QUOTE From: Dale McCoy (dalestan_at_[hidden]) Date: 2006-04-22 21:15:51 I'm trying to convert from getopt (GNU's getopt_long, to be more specific) to boost::program_options, but have run into trouble converting "D::" and {"data",optional_argument,NULL,'D'} (If you're not familiar with getopt, that means that --data is equivalent to -D, and both take an optional argument, so "-D", "--data", "-Darg", and "--data=arg" are all valid.) I see that the first argument to add_option should be "data,D", but then things get fuzzy. I saw nothing in the documentation concerning optional arguments, either directly, or using additional parsers. What is the appropriate method for implementing such options? I'm using currently using Boost 1.33.1. Dale END QUOTE Bryan
On 6/12/07, Bryan Green
Hello,
Is there a mechanism in boost::program_options for supporting optional arguments? If not, is there a suggested program_options-based alternative?
What exactly do you mean by optional arguments? Do you mean like this? http://www.boost.org/doc/html/program_options/howto.html#id1593176 Chris
"Chris Weed" writes:
On 6/12/07, Bryan Green
wrote: Hello,
Is there a mechanism in boost::program_options for supporting optional arguments? If not, is there a suggested program_options-based alternative?
What exactly do you mean by optional arguments? Do you mean like this? http://www.boost.org/doc/html/program_options/howto.html#id1593176
Chris
The quotation in my email goes into exact detail - basically, I'm looking
for functionality equivalent to GNU getopt_long, which has an
"optional_argument" specifier. It is a method for optionally associating a
value with a particular option.
For example, if I specify a getopt_long parameter to enable listening on a
socket:
{"listen",optional_argument,NULL,'l'}
Then, on the command line,
'--listen' means to enable listening, using a default port number.
'--listen=5000' means enable listening, using port number 5000.
The only way I see to accomplish this with program_options is to make a
second option called "listen_port".
I've been playing with 'po::value
I am at a loss of how to do that.
Hopefully someone else can give you a hand.
Chris
On 6/12/07, Bryan Green
"Chris Weed" writes:
On 6/12/07, Bryan Green
wrote: Hello,
Is there a mechanism in boost::program_options for supporting optional arguments? If not, is there a suggested program_options-based alternative?
What exactly do you mean by optional arguments? Do you mean like this? http://www.boost.org/doc/html/program_options/howto.html#id1593176
Chris
The quotation in my email goes into exact detail - basically, I'm looking for functionality equivalent to GNU getopt_long, which has an "optional_argument" specifier. It is a method for optionally associating a value with a particular option. For example, if I specify a getopt_long parameter to enable listening on a socket:
{"listen",optional_argument,NULL,'l'}
Then, on the command line, '--listen' means to enable listening, using a default port number. '--listen=5000' means enable listening, using port number 5000.
The only way I see to accomplish this with program_options is to make a second option called "listen_port".
I've been playing with 'po::value
()->zero_tokens()', but it does not work as I had hoped. I don't really understand how 'zero_tokens' is supposed to work, frankly. It seems to be useful when the value type is 'bool', but I don't understand its use for non-boolean types. -Bryan
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
"Chris Weed" writes:
I am at a loss of how to do that. Hopefully someone else can give you a hand. Chris
On 6/12/07, Bryan Green
wrote: "Chris Weed" writes:
On 6/12/07, Bryan Green
wrote: Hello,
Is there a mechanism in boost::program_options for supporting optional arguments? If not, is there a suggested program_options-based alternat ive?
What exactly do you mean by optional arguments? Do you mean like this? http://www.boost.org/doc/html/program_options/howto.html#id1593176
Chris
The quotation in my email goes into exact detail - basically, I'm looking for functionality equivalent to GNU getopt_long, which has an "optional_argument" specifier. It is a method for optionally associating a value with a particular option. For example, if I specify a getopt_long parameter to enable listening on a socket:
{"listen",optional_argument,NULL,'l'}
Then, on the command line, '--listen' means to enable listening, using a default port number. '--listen=5000' means enable listening, using port number 5000.
The only way I see to accomplish this with program_options is to make a second option called "listen_port".
I've discovered that this does not work either, because if you try to specify the '--listen' option, it complains that it is ambiguous. Is there any more information on how the 'zero_tokens' flag is supposed to behave for non-boolean types? -Bryan
participants (2)
-
Bryan Green
-
Chris Weed