[gdal-dev] Using a "standard" argument parser for command line utilities?
Andrew C Aitchison
andrew at aitchison.me.uk
Fri Mar 8 08:45:20 PST 2024
On Fri, 8 Mar 2024, Even Rouault via gdal-dev 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
Some options have related environment variables, eg --debug /CPL_DEBUG.
Options are also passed through to several drivers.
I assume that the implications for these are not significant ?
--
Andrew C. Aitchison Kendal, UK
andrew at aitchison.me.uk
More information about the gdal-dev
mailing list