cxxopts icon indicating copy to clipboard operation
cxxopts copied to clipboard

Add a print function for the option object

Open cyang-kth opened this issue 4 years ago • 4 comments

I think that a print() function can be useful to print out the configurations parsed by the user. The description can be reused during the printing.

cxxopts::Options options;
auto result = options.parse(argc, argv);
options.print(result);

cyang-kth avatar Mar 02 '20 11:03 cyang-kth

What sort of information would you like printed that would be different from what help prints?

jarro2783 avatar Mar 02 '20 21:03 jarro2783

@jarro2783

The current help print like this

      --log_level arg         Log level (default: 3)
      --network arg           Network file name
      --id arg                Network id name (default: id)

When the user types

--log_level 5 --network foo.txt --id gid

I would like to have

      --log_level arg         5
      --network arg           foo.txt
      --id arg                gid

I frequently encounter this need when I want to confirm the input argument is correct and record it in the log file.

cyang-kth avatar Mar 03 '20 08:03 cyang-kth

For what it is worth, in the last project where I used cxxopts, I wrote code nearly identical to this. Before beginning a long period of computation, I had it list all the parameters it was using.

cwreynolds avatar Mar 03 '20 16:03 cwreynolds

Ok that makes. So you actually want it to print out the ParseResult object so you know what it has actually parsed.

jarro2783 avatar Mar 03 '20 21:03 jarro2783