[program_options] Feature request: settable argument names

I recently used the program_options library for the first time and found it very useful. However, there's one easily implemented feature that's missing: the ability to set the name of a parameter that's associated with a particular option. In the first example in the tutorial we have the code po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("compression", po::value<int>(), "set compression level") ; When desc is then sent to cout, the output then looks like Allowed options: --help : produce help message --compression arg : set compression level But suppose we wanted the name of the parameter associated with the --compression option to be something other than arg. As program_options is now written there's no way to do this. This is unfortunate, because replacing arg with a more relevant argument name could make it clearer to the user what type of values should be passed in. I suggest adding the following member to the typed_value template class: typed_value *argument_name(const std::string &); This function would change the name of the arguement associated with the option from "arg" to whatever string was passed in. If it isn't called then the argument name can remain as "arg". If this function were included, then the code above could be rewritten as po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("compression", po::value<int>()->argument_name("level-number"), "set compression level") ; and then the output would be Allowed options: --help : produce help message --compression level-number : set compression level Joe Gottman

Joe Gottman wrote:
I recently used the program_options library for the first time and found it very useful. However, there's one easily implemented feature that's missing: the ability to set the name of a parameter that's associated with a particular option. In the first example in the tutorial we have the code
po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("compression", po::value<int>(), "set compression level") ;
When desc is then sent to cout, the output then looks like
Allowed options: --help : produce help message --compression arg : set compression level
But suppose we wanted the name of the parameter associated with the --compression option to be something other than arg.
I intentionally did not add that bit of flexibility, as I though that configurable 'arg' is not adding all that much to legibility. Do you have some concrete examples?
If this function were included, then the code above could be rewritten as
po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("compression", po::value<int>()->argument_name("level-number"), "set compression level") ;
and then the output would be
Allowed options: --help : produce help message --compression level-number : set compression level
Well, here, I don't like the duplication between 'level' and 'level-number' Maybe it would be cleaner to have just: --compression arg : set compression level (0-9) or some such? - Volodya
participants (2)
-
Joe Gottman
-
Vladimir Prus