0

I am writing a new implementation of existing software (clean room implementation so no access to old code) and as well as a new command line interface I need to emulate the old interface for compatibility with existing workflows. I am choosing between old and new interface depending on the name with which the executable is invoked like e.g busybox.

The old command line interface essentially uses key value pairs but without any '-' or '=' characters. e.g

./oldcode Key1 value1 Key2 value2 Key3 value3 ...

I am already using boost so would like to stick with program_options if I can. The easiest thing would be to simply parse options without requiring and '--' at the beginning of the argument but I cannot see a way to do this.

Is this feasible with program_options or would I be better off writing a custom parser for this?

PTooley
  • 383
  • 3
  • 11
  • "but I cannot see a way to do this" ... `main( int argc, char* argv[])` gives you all you need already. `argv[1]` is the first key, `argv[2]` the first value, `argv[3]` the second key etc. – Rene Nov 20 '18 at 13:24
  • Well naturally, but as I said, I would like to use program_options is possible. As well as autogenerating the usage messages, it makes things easier down the line having only one interface to get my configuration from. – PTooley Nov 20 '18 at 13:47
  • Sure, but then you would have to use the standard format for program arguments. The only possibility I see is to store all arguments you get as positional arguments in a vector, and then get the key-value pairs from this vector. – Rene Nov 20 '18 at 14:31

1 Answers1

0

You have to write a custom parser for it, it is not that hard :) Especially, when you what you find.

The boost mechanism excepted the = sing for key,value pairs.

If you do not want to write it own, use the the existing code: https://github.com/jarro2783/cxxopts

György Gulyás
  • 1,290
  • 11
  • 37