cxxopts icon indicating copy to clipboard operation
cxxopts copied to clipboard

Split cxxopts.hpp into multiple files

Open eyalroz opened this issue 2 years ago • 4 comments

One can observe a decomposition of cxxopts.hpp into several parts:

  • non-option-specific string-related code
  • Exception-related code
  • the values namespace and the Value class
  • KeyValue, Option, OptionParser and related code
  • ParseResult and some Option/OptionParser implementations which need ParseResult
  • Options, OptionAddr, help

And the above is also the order of dependencies.

Or, actually, maybe we could take this another step and have one file per (non-trivial) class, so separate files for Option, Option Adder, Options, OptionParser etc.

So, how about we split the huge single file into a file for each of these? With cxxopts.hpp remaining as an "includer" of all the others?

This will:

  • Improve source code readability
  • Make it easier to merge changes
  • Make the revision history easier to understand (when looking at the affected files)

What do you think, @jarro2783 ?

eyalroz avatar Jul 06 '22 21:07 eyalroz

I always wanted this to be single header to just drop into a project, and it still doesn't seem huge yet. If there was a nice way to generate a single header then I think it could be broken up.

jarro2783 avatar Jul 08 '22 00:07 jarro2783

@jarro2783 : Why is it important to be able to drop a single file rather than a subfolder?

Anyway, to create a single header, you run:

quom cxxopts.hpp cxxopts_single.hpp

and you get quom with:

pip3 --user install quom

See also: https://stackoverflow.com/a/62218074/1593077

eyalroz avatar Jul 08 '22 07:07 eyalroz

Yeah I guess having multiple files is not so bad. I'll look at this after some of the other changes because it will mess up PRs.

jarro2783 avatar Jul 10 '22 20:07 jarro2783

So, yeah, the different PRs tend to clash. When you decide which of them you like, I'll rebase them onto each other so that you can merge.

eyalroz avatar Jul 10 '22 21:07 eyalroz