Boost logo

Boost :

From: Jens Maurer (jmaurer_at_[hidden])
Date: 2000-05-04 16:31:00


Daniel Heck wrote:
> [...] POSIX style command
> line parser (somewhat similar to getopt, but written in C++ and not
> reliant upon global variables). I thought it might be useful for
> other people, but I'm not quite sure whether or not such a library
> would be inside boost's scope or even desired...

In general, I think a boost command-line parser would be
helpful. However, command-line options are usually a once-only
thing, so using POSIX getopt (with its global state) may not
be that inconvenient.

Here is what I had in mind before Daniel's post came up:
 - Iterator for iterating through the arguments
 - Possibly transparent redirection support for operating
systems with limited command-line length. (i.e. read your
command-line options from a file) (not a high priority)
 - Error reporting with exceptions
 - Possibly a wrapper around all this for mapping
options to lambda-expressions. (cf. signal/slot library)
Usage vision for this:
opt.define("-o", "--output", bind(&set_output_filename, free1))

Here are a few comments regarding your argp.hh. Please don't
be disappointed, but do pursue this matter.

> #ifndef __ARGP_HH
> #define __ARGP_HH

Identifiers starting with two underscores are reserved
for the implementation (of C++), so don't use them as
include guards (popular misfeature).

Of course, everything should be put into namespace boost
for submission. Do check the other submission guidelines
as well.

> list<string> _arglist;
> list<string> _arguments;

Please prefix identifiers from the standard library with
"std::", otherwise the program is non-conformant. (I can't see
a "using namespace std" anywhere, and I would like it, either.)

> bool getopt(option& opt);

As said before, I think an iterator-based interface
(for the linear sequence of command-line arguments) is more
in the spirit of C++ and its library.

I'm unsure whether problems with the command line should be
reported by a return value or by an exception.

Btw, I don't think your getopt handles command-lines such as
"-hvo file.txt", i.e. merging of bool one-char options.
This would be useful.

Jens Maurer


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk