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

Even Rouault even.rouault at spatialys.com
Mon Mar 11 15:23:40 PDT 2024


Hi,

I've had some success prototyping the below idea on a few utilities. See 
https://github.com/OSGeo/gdal/pull/9445 for details

Even

Le 08/03/2024 à 16:40, Even Rouault via gdal-dev a écrit :
>
> 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

-- 
http://www.spatialys.com
My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240311/bbbe06e7/attachment.htm>


More information about the gdal-dev mailing list