-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add suggestions for unrecognized command line options. #526
Conversation
nameStrip.erase(std::remove(nameStrip.begin(), nameStrip.end(), '-'), | ||
nameStrip.end()); | ||
|
||
// Also suggest options containing the substring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these suggestions should go first
|
||
throw po::error(errorMessage); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to a separate _processUnrecognizedOptions function?
col[0] = i + 1; | ||
for (unsigned int j = 0; j < len2; j++) | ||
// note that std::min({arg1, arg2, arg3}) works only in C++11, | ||
// for C++98 use std::min(std::min(arg1, arg2), arg3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
// Merge suggestions giving precedence to substrings | ||
auto output = subStringOptions; | ||
output.insert(std::end(output), std::begin(levenshteinOptions), | ||
std::end(levenshteinOptions)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment, why do you use std::end(..) instead of calling foo.end()? I would understand it in a template function, but here it makes the code less readable. I'd even say the same for using insert.
Don't you find this more readable and shorter to type:
for (const auto& option : levenshteinOptions)
output.push_back(option)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is better. I would like to see a 'vector += other_vector' or 'vector.append(other_vector)' in the standard library.
constexpr size_t MAX_SUGGESTIONS = 7; | ||
|
||
for (const auto& optionName : options) | ||
std::vector<std::string> subStringOptions; | ||
std::vector<std::string> levenshteinOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why two vectors that need concatenation later on? The original code was fine, I was just suggesting to move the substrings options up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is easier to just keep them separated since then I can clear just the levenshtein vector in the loop.
void ParametersManager::_processUnrecognizedOptions( | ||
const std::vector<std::string>& unrecognizedOptions) const | ||
{ | ||
if (!unrecognizedOptions.empty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (unrecognizedOptions.empty())
return;
Example: