When using boost::program_options
, how do I set the name of an argument for boost::program_options::value<>()
?
#include
In the current version of boost (1.53) you don't need anymore to make your own class as Tim Sylvester proposed. It's possible to use : boost::program_options::typed_value. On which value_name can be configured.
#include
#include
using boost::program_options::typed_value;
using boost::program_options::options_description;
int main(int argc, char **argv) {
options_description desc("Usage");
int someValue;
auto someOption = new typed_value(&someValue);
someOption->value_name("NUM");
desc.add_options()
("some-option,s", someOption, "The option\n");
std::cout << desc << std::endl;
return 0;
}
Will display a configured argument name :
Usage:
-s [ --some-option ] NUM The option