0

One of the things I want to do when I use Program Options is to print the help string according to the styles I want to enforce. For example, on Windows if I use:

allows_slash_for_short

it will make sense for me to reflect that when I print the actual help string. I can't find a way to do this. In fact it doesn't seem to be supported. I noticed that the:

option_description::format_name() 

method, which is called to format each option while streaming the help message, hard codes the leading characters of the long and short options and as a result there is no way to print the description based on the style I am enforcing. This seems like a serious bug to me.

Here is some code to illustrate what I am trying to do:

namespace po = boost::program_options; 
namespace postyle = boost::program_options::command_line_style;

po::options_description desc(“Options”);
po.add_options()
        ("xxxx,X", Xhook, "Desc")
        ("yyyy,Y", Yhook, "Desc")
        ("zzzz,Z", Zhook, "Desc");

int unix_style = postyle::unix_style|postyle::short_allow_next;
int windows_style = postyle::allow_long|
                    postyle::allow_short|
                    postyle::allow_slash_for_short|
                    postyle::allow_slash_for_long|
                    postyle::case_insensitive|
                    postyle::short_allow_next|
                    postyle::long_allow_next;

po::variables_map vm;

try {
  po::store(
    po::command_line_parser(argc, argv)
           .options(desc)
           .style(windows_style)  // tell the parser the style of the input
           .run(), vm);
  po::notify(vm);

  if (argc == 1 || vm.count("help")) {
    std::cout << "USAGE: " << argv[0] << '\n'
              << desc << '\n';    // prints the command-line in canonical form
                                  // without applying the right style
    return 0;
  }
} catch (po::error& poe) {
  ...
}
CppNoob
  • 2,322
  • 1
  • 24
  • 35

0 Answers0