osm2pgsql accepts multiple conflicting arguments
(moved here from https://trac.openstreetmap.org/ticket/2810)
by accident, I specified the -O twice, but got no warning. this is bad : ./osm2pgsql -O gazetteer -U gis -H localhost -lsc -O pgsql -C 2000 -d gisdb test.osm.bz2
osm2pgsql should check for duplicate and conflicting arguments, I can make a patch for this if needed.
mike
Confirming this still happens. It would also be the case for -l/-m/-E, -p, -d, -C and plenty of other options.
Do we want to solve this? It might help with command-line mistakes.
Yes, it would be nice to have.
Perhaps we should move to boost::program_options or something which takes care of this for us? Otherwise, we're looking at adding checks to a dozen options.
As @pnorman mentioned many years ago we should switch to a better command line option parsing library to solve this. I see two real options:
I have looked at many other options and used some of them, but they are either not powerful enough, not well maintained or not widely available in packages.
I have used Boost Program Options in other programs and am not really happy, the functionality is good, but the syntax is verbose and very hard to read. CLI11 looks better in that regard but I have only played around with it a bit, not really used it. But "The Internet" seems to be quite happy with it.
As far as I can see, the largest downside of CLI11 is that it is another new dependency, the boost dependency we have anyway. On the other hand, the boost program options library is a compiled library while CLI11 is header only, so somewhat easier to install. (This doesn't matter currently, because we use other Boost libraries that are not header only, but medium term we should be able to get rid of boost system and boost filesystem (because those things are available in modern C++ std libs) and leaves only header-only boost components.
There is a good comparison of boost po and CLI11 here: https://iscinumpy.dev/post/comparing-cli11-and-boostpo/