Skip to content
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

Merged
merged 3 commits into from
Aug 20, 2018

Conversation

karjonas
Copy link
Contributor

Example:

[ERROR] Unrecognized option '--mode'.

Most similar options are:
	--module
	--synchronous-mode
	--circuit-uses-simulation-model
	--memory-mode

@karjonas karjonas requested a review from favreau August 20, 2018 09:46
nameStrip.erase(std::remove(nameStrip.begin(), nameStrip.end(), '-'),
nameStrip.end());

// Also suggest options containing the substring
Copy link
Contributor

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);
}

Copy link
Contributor

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)
Copy link
Contributor

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));
Copy link
Contributor

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)

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (unrecognizedOptions.empty())
    return;

@karjonas karjonas requested a review from hernando August 20, 2018 12:02
@karjonas karjonas merged commit 201c3b2 into BlueBrain:master Aug 20, 2018
@karjonas karjonas deleted the suggestions branch August 22, 2018 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants