CLIUtils / CLI11

CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface.
https://cliutils.github.io/CLI11/book/
Other
3.29k stars 347 forks source link

Print argv from a callback #1063

Closed eolivi-fy closed 1 week ago

eolivi-fy commented 1 month ago

Hi first of all, thank you for this good library!

I'd like to be able to print the command run:

> ./MyBinary --input file.txt --num 4 --log debug
Command run was: "./MyBinary --input file.txt --num 4 --log debug"
...

Of course I could simply call:

for (int i = 0; i < argc; i++)
   std::cout << argv[i] << " ";

// just before
app.parse(argc, argv);

But I feel there could be a way using a callback ?

This does it almost:

app.parse_complete_callback([&app](){
   std::cout << "Command run:\n" << app.config_to_str()) << std::endl;
}

Command run: log="debug" input="file.txt" num=4

maybe there is another way ?

phlptp commented 4 weeks ago

I don't think a way was built to regenerate the command line directly inside CLI11.

eolivi-fy commented 4 weeks ago

Thanks, good enough then with app.config_to_str()

Feel free to close