Boost logo

Boost Users :

From: Bryan Green (bgreen_at_[hidden])
Date: 2007-08-07 16:38:33


Vladimir Prus writes:
> Bryan Green wrote:
>
> >
> > Attached is a patch to program_options that implements optional argument
> > support, in the style of GNU getopt_long. It adds one new method to
> > 'value_type': 'implicit_value()'.
>
>
> 2. In value_semantics.hpp, you have this:
>
> - if (!m_default_value.empty() && !m_default_value_as_text.empty()) {
> + if (!m_implicit_value.empty() && !m_implicit_value_as_text.empty())
> {
> + return "[=arg] (=" + m_implicit_value_as_text + ")";
> + }
>
> So apparently, if implicit value is provided, the default value is
> not shown? Is this intended, and why is this good?

Well, the assumption I'm making is that when using an implicit argument, the
default argument (if given) is not of interest to the user, but is just a
convenience to the programmer, since it makes the 'vm.count("arg")'
test unnecessary.

In general, it seems that the "default value" is fairly implicit given the
context of the option - it usually means "don't do anything in this regard".

However, I suppose the library is more flexible if such an assumption was
not made. I'll try the alternative in an updated patch.

Just to provide some real world examples, for context:

>From GNU sed:

       -i[SUFFIX], --in-place[=SUFFIX]

                     edit files in place (makes backup if extension
                     supplied)

>From GNU rm:

       --interactive[=WHEN]
              prompt according to WHEN: never, once (-I), or always (-i).
              Without WHEN, prompt always

>From GNU uniq:

       -D, --all-repeated[=delimit-method]
              print all duplicate lines
              delimit-method={none(default),prepend,separate} Delimiting is
              done with blank lines.

The color option for GNU ls:

       --color[=WHEN]
                     control whether color is used to distinguish file
                     types. WHEN may be `never', `always', or `auto'
  ...
  The man page then goes into detail at the end of the section:

       By default, color is not used to distinguish types of files. That is
       equivalent to using --color=none. Using the --color option without the
       optional WHEN argument is equivalent to using --color=always. With
       --color=auto, color codes are output only if standard output is con-
       nected to a terminal (tty). The environment variable LS_COLORS can
       influence the colors, and can be set easily by the dircolors command.

Regards,
Bryan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net