vietjtnguyen / argagg

A simple C++11 command line argument parser
MIT License
224 stars 28 forks source link

Get rid of definition names, key by the option itself #14

Open vietjtnguyen opened 6 years ago

vietjtnguyen commented 6 years ago

I realized that the definition name isn't really needed. I used it because I wanted a name to key on so that you can reference the option's parse results using that name, but why not just reference the option by any one of the options' flags? So instead of

//...
  parser argparser {{
//...
      {
        "sep", {"-s", "--sep"},
        "separator (default ',')", 1},
//...
    }};
//...
  auto sep = args["sep"].as<string>(",");
//...

you can just do

//...
  parser argparser {{
//...
      {
        {"-s", "--sep"},
        "separator (default ',')", 1},
//...
    }};
//...
  auto sep = args["--sep"].as<string>(",");
  // or alternatively...
  //auto sep = args["-s"].as<string>(",");
//...

The option name isn't really used for anything else.