[gdal-dev] Using a "standard" argument parser for command line utilities?

Javier Jimenez Shaw j1 at jimenezshaw.com
Fri Mar 8 09:01:17 PST 2024


Hi Even.

In principle the idea sounds good.

How is it parsing the numbers? is it locale agnostic? I think it is not,
because it is using "strtod". That means that if I have my locale in
Spanish, French, German, ... it will expect "," as the decimal separator,
right?
... well, how is GDAL expecting floating values? Is GDAL locale agnostic?

Do you want to add it as a dependency, or just copy-paste the header file
into gdal repo?

On Fri, 8 Mar 2024 at 16:40, Even Rouault via gdal-dev <
gdal-dev at lists.osgeo.org> wrote:

> Hi,
>
> Our command line C++ utilities use ad-hoc manual parsing, which means that:
>
> -  the usage message must be manually composed,
>
> -  you must take care to check that there are enough remaining arguments
> for the ones that take value to avoid out-of-bounds accesses (tests like
> argc + 1 < argn)
>
> - detection for duplicated arguments when only a single occurrence is
> allowed must be manually done, nd thus is often not done, confusing users,
> cf https://github.com/OSGeo/gdal/issues/9415
>
> - etc.
>
> I've come across https://github.com/p-ranav/argparse which fit all my
> requirements at first sight: compatible with our C++ requirements (C++17),
> MIT license, easily usable (single header), well documented, and enough
> feature-full. From a quick testing, it seems to work well. It looks also as
> it has taken some inspiration from the Python argparse module.
>
> I'd be tempted to give that a try to retrofit our existing utilities
> (probably starting with the ones with the less options :-)). Opinions? I
> guess there must be a plethora of similar projects, due to the absence of a
> std::argparse module... At least I see it is in the list of (9)
> alternatives mentioned at
> https://en.cppreference.com/w/cpp/links/libs?source=post_page---------------------------#Configuration:Command_Line
>
> CLI11 looked like a candidate too, but reading
> https://github.com/CLIUtils/CLI11?tab=readme-ov-file#features-not-supported-by-this-library
> "There are some other possible "features" that are intentionally not
> supported by this library:... Non-standard variations on syntax, like
> -long options. This is non-standard and should be avoided, so that is
> enforced by this library." . Fair enough, but we use that extensively in
> GDAL.
>
> Even
>
> -- http://www.spatialys.com
> My software is free, but my time generally not.
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240308/34912573/attachment-0001.htm>


More information about the gdal-dev mailing list