Skip to content

Commit

Permalink
Allow to type the entire version when conflict occured (#2243)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpunkfu authored and sheerun committed Apr 10, 2016
1 parent 3251051 commit 7c54812
Showing 1 changed file with 17 additions and 3 deletions.
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

0 comments on commit 7c54812

Please sign in to comment.