Opened 18 years ago

Closed 15 years ago

#342 closed Support Requests (duplicate)

program_options Can one have options with optional values?

Reported by: nobody Owned by: Vladimir Prus
Milestone: Component: program_options
Version: None Severity: Problem
Keywords: Cc:

Description

Hello,

I was wondering if it is possible to have an option for
which supplying an argument is optional.  For example,
suppose I have an executable called myprog and an
option "o" that does something.  Is it possible to
allow both of the following command line syntaxes?

myprog --o arg
myprog --o

Where in the second case I can programatically supply
some default value?

So the first would instruct the program to take the
action associated with the "o" option using the
supplied arg and the second would instruct it to take
that action using the default argument value.

I have been fooling with the default_value and implicit
methods but neither seems to do what I want. 

Thanks,
John Eddy
johneddy@eng.buffalo.edu

Change History (3)

comment:1 by rleigh@…, 15 years ago

This is a feature I would also find most useful. In my case, I would like to have an option:

--run-session

but also allow the user to specify an optional session name

--run-session=session-name

and if this is missing, I will compute one automatically.

GNU getopt_long has the concept of "required" and "optional" arguments. It would be nice if typed_value/value_semantic had an optional() method and member to permit this.

Regards, Roger

comment:2 by Daryle Walker, 15 years ago

Component: Noneprogram_options
Severity: Problem

comment:3 by Vladimir Prus, 15 years ago

Resolution: Noneduplicate
Status: assignedclosed

Superseded by #1131.

Note: See TracTickets for help on using tickets.