catchorg / Clara

A simple to use, composable, command line parser for C++ 11 and beyond
Boost Software License 1.0
648 stars 67 forks source link

Parsing `-j 8` but also `-j8` #70

Open daminetreg opened 6 years ago

daminetreg commented 6 years ago

Dear Clara authors,

First thanks for this lightweight cmdline parsing library. It's much appreciated after years of program_options. :wink:

I'm using Clara and I noticed that most of the time I mistype the command line argument without space between the value and the option.

Is there an easy way or could you give some hints to make a patch, so that -j 8 but also -j8 could be parsed as 8 for a case like this :

  std::optional<size_t> cpus_j;
  auto cmd_args =
      Opt ( cpus_j, "cpus" )
          ["-j"]
          ("How many CPU cores have to be dedicated to the build.\n");

Or is it something you don't want at all in Clara ?

Warm regards,

philsquared commented 6 years ago

The trouble is that, after a - multi-character arguments are treated as a series of single character options. E.g. -abc is the equivalent of passing -a -b -c. So -j8 would be interpreted as -j -8. If you didn't want that behaviour we could, perhaps, include an option (a #define) to disable it - in favour of your behaviour. But that would complicate things. And at the moment we have more pressing changes to make.

We do also support -j=8 and -j:8, however.

daminetreg commented 6 years ago

Thanks for the short response time. :+1:

We do also support -j=8 and -j:8, however.

Yes but it requires to type more for the user of the command line.

Wouldn't it be an option to have -abc work at the same time than -j8 because b and c are known as options, while 8 isn't ?

Or simply because 8 is a numeral and therefore it isn't a wish to support it as arg ?

grafikrobot commented 4 years ago

This is now supported in Lyra as of https://github.com/bfgroup/Lyra/commit/8013cbae5a320c0c83bd9bebdde57f7f20f236d7

daminetreg commented 4 years ago

Hey thanks René, I‘ll try your fork! Boost philosophy is great!