<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi,</p>
<p>Our command line C++ utilities use ad-hoc manual parsing, which
means that:</p>
<p>- the usage message must be manually composed, </p>
<p>- 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) </p>
<p>- detection for duplicated arguments when only a single
occurrence is allowed must be manually done, nd thus is often not
done, confusing users, cf
<a class="moz-txt-link-freetext" href="https://github.com/OSGeo/gdal/issues/9415">https://github.com/OSGeo/gdal/issues/9415</a></p>
<p>- etc.<br>
</p>
<p>I've come across <a class="moz-txt-link-freetext" href="https://github.com/p-ranav/argparse">https://github.com/p-ranav/argparse</a> 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.<br>
</p>
<p>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
<a class="moz-txt-link-freetext" href="https://en.cppreference.com/w/cpp/links/libs?source=post_page---------------------------#Configuration:Command_Line">https://en.cppreference.com/w/cpp/links/libs?source=post_page---------------------------#Configuration:Command_Line</a></p>
<p>CLI11 looked like a candidate too, but reading
<a class="moz-txt-link-freetext" href="https://github.com/CLIUtils/CLI11?tab=readme-ov-file#features-not-supported-by-this-library">https://github.com/CLIUtils/CLI11?tab=readme-ov-file#features-not-supported-by-this-library</a>
"There are some other possible "features" that are intentionally
not supported by
this library:... Non-standard variations on syntax, like <code>-long</code>
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.<br>
</p>
<p>Even<br>
</p>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>