vietjtnguyen / argagg

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

Optional argument param #16

Closed apavlenko closed 6 years ago

apavlenko commented 6 years ago

Is it possible to support an optional argument for parameter? E.g. it should be possible to use both --log and --log=errors-only (the 1st variant assumes some default level)

nlappas commented 6 years ago

You can always handle it in your code

int logLvl = 0;   // Off by default
if(args["log"]) {
   logLvl = 3;   // Enable default level
   if(args["log"].as<std::string>()=="errors-only") logLvl = 1;  // Use custom
}
vietjtnguyen commented 6 years ago

Yea, my concern with having that style of optional argument is that it actually introduces a third state to the flag. Also, it messes with the current greedy argument behavior. For example, foo --log --verbose would make --verbose an argument to --log.

Currently a flag has two states:

I feel like if there's some default behavior you want with a flag specified with no argument it can be captured by its own flag. Consider git log for example, --oneline is equivalent to --pretty=oneline.

vietjtnguyen commented 6 years ago

I'm going to close this for now though I'm open to further discussion in this issue.