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

implement the possibility to type the entire version when conflict occured #2243

Merged
merged 1 commit into from Apr 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/core/Manager.js
Expand Up @@ -678,6 +678,8 @@ Manager.prototype._electSuitable = function (name, semvers, nonSemvers) {
var save;
var choices;
var picks = [];
var versionRegex = /(?:[\d\w]\.){2}[\d\w](?:.)*/;
var picksReleases;

// If there are both semver and non-semver, there's no way
// to figure out the suitable one
Expand Down Expand Up @@ -833,14 +835,21 @@ Manager.prototype._electSuitable = function (name, semvers, nonSemvers) {
});

choices = picks.map(function (pick, index) { return index + 1; });
picksReleases = picks.map(function(pick) { return pick.pkgMeta._release; });
return Q.nfcall(this._logger.prompt.bind(this._logger), {
type: 'input',
message: 'Answer',
validate: function (choice) {
var invalidChoice = 'Invalid choice';

if (choice.match(versionRegex)) {
return picksReleases.indexOf(choice) != -1 ? true : invalidChoice;
}

choice = Number(mout.string.trim(choice.trim(), '!'));

if (!choice || choice < 1 || choice > picks.length) {
return 'Invalid choice';
return invalidChoice;
}

return true;
Expand All @@ -852,8 +861,13 @@ Manager.prototype._electSuitable = function (name, semvers, nonSemvers) {
// Sanitize choice
choice = choice.trim();
save = /^!/.test(choice) || /!$/.test(choice); // Save if prefixed or suffixed with !
choice = Number(mout.string.trim(choice, '!'));
pick = picks[choice - 1];

if (choice.match(versionRegex)) {
pick = picks[picksReleases.indexOf(choice)];
} else {
choice = Number(mout.string.trim(choice, '!'));
pick = picks[choice - 1];
}

// Save resolution
if (save) {
Expand Down