cpp icon indicating copy to clipboard operation
cpp copied to clipboard

Add recommendations for option parsing

Open springmeyer opened this issue 8 years ago • 7 comments
trafficstars

In C++ my experience says:

  • If it is okay to use boost, use boost::program_options, it is a solid library.
  • It is often not okay to use boost. The headers alone are > 50 MB 🙀 and contain > 13,000 files. And boost::program_options requires linking a precompiled library. This is massive weight and complexity for a build system just to parse options.
  • So for lightweight C++ libs that might not otherwise have any dependencies we need to recommend a very lightweight option parsing solution.

/cc @GretaCB @joto @mapbox/core-tech @danpat

springmeyer avatar Sep 10 '17 00:09 springmeyer

libraries to investigate:

  • https://github.com/jarro2783/cxxopts
  • http://optionparser.sourceforge.net/
  • https://github.com/myint/optparse

springmeyer avatar Sep 10 '17 01:09 springmeyer

I usually just use getopt_long() available in libc for simpler cases. The interface is C and not C++ and slightly ugly. But for many cases this is simple enough and doesn't require an extra dependency. If this is not enough it is time to switch to boost::program_options anyway.

joto avatar Sep 10 '17 09:09 joto

Something to investigate: Clara "A simple to use, composable, command line parser for C++ 11 and beyond". By the same guy who created the Catch unit test framework.

joto avatar Nov 07 '17 08:11 joto

Just learned from @kkaefer that mbgl is using https://github.com/Taywee/args for demo apps - which @brunoabinader brought in.

springmeyer avatar Jan 04 '18 21:01 springmeyer

watching progress on Clara at https://github.com/mapbox/vtzero/commit/70fc23278e45788bf4812cb22d888ea024dc9c65. I'm in support for having Clara be our recommendation if @joto's experience is solid this week in this port.

springmeyer avatar Feb 21 '18 16:02 springmeyer

My experience with Clara so far:

Positive:

  • Easy to use, clean code.
  • Easy to integrate 42k header file.
  • In active development.

Negative:

  • Documentation is not complete.
  • Still in development, changes to be expected.
  • Single - char as parameter (often used to denote stdin) is not possible.

I think it is too early to recommend this as a standard tool, but I think collecting some experience with it is probably a good idea. (That's why I went ahead and used it in the relatively simple vtzero examples.)

joto avatar Feb 22 '18 08:02 joto

I think collecting some experience with it is probably a good idea. (That's why I went ahead and used it in the relatively simple vtzero examples.)

👍 looking forward to learning more as you use it.

springmeyer avatar Feb 22 '18 17:02 springmeyer