Skip to content

Commit

Permalink
fix(doctor): fix prompting and error handling with --no-prompt
Browse files Browse the repository at this point in the history
closes #410
- throw errors instead if prompts are disabled
- fix error if remote mysql host is used
  • Loading branch information
acburdine committed Jul 31, 2017
1 parent 106f4e8 commit 1641676
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lib/commands/doctor/checks/install.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
'use strict';
const fs = require('fs');
const os = require('os');
const eol = require('os').EOL;
const path = require('path');
const Mode = require('stat-mode');
const chalk = require('chalk');
const execa = require('execa');
const semver = require('semver');
const constants = require('constants');
const isRoot = require('path-is-root');
const includes = require('lodash/includes');

const errors = require('../../../errors');
const cliPackage = require('../../../../package');

const eol = os.EOL;

function checkDirectoryAndAbove(dir) {
if (isRoot(dir)) {
return;
Expand Down Expand Up @@ -106,14 +108,22 @@ module.exports = [{
'yellow'
);

return ctx.ui.confirm(chalk.blue('Continue anyway?'), false);
return ctx.ui.allowPrompt ? ctx.ui.confirm(chalk.blue('Continue anyway?'), false) : Promise.resolve({yes: false});
}).then(answer => answer.yes || Promise.reject(
new errors.SystemError('System checks failed.')
));
}
}, {
title: 'Checking MySQL is installed',
skip: (ctx) => ctx.local || (ctx.argv && ctx.argv.db === 'sqlite3'),
skip: (ctx) => {
// Skip this check if:
// a) local install OR
// b) --db sqlite3 is passed OR
// c) --dbhost is passed and IS NOT 'localhost' or '127.0.0.1'
return ctx.local ||
(ctx.argv && ctx.argv.db === 'sqlite3') ||
(ctx.argv && ctx.argv.dbhost && !includes(['localhost', '127.0.0.1'], ctx.argv.dbhost));
},
task: (ctx) => {
// On ubuntu, mysqld is in `/usr/sbin` but it's not automatically in the PATH of non-root users
// So, we modify the path env var to make things work
Expand All @@ -130,10 +140,13 @@ module.exports = [{
`${chalk.blue('c)')} run ${chalk.cyan('`ghost install local`')} to get a development install using sqlite3.`
);

return ctx.ui.confirm(chalk.blue('Continue anyway?'), false)
.then(answer => answer.yes || Promise.reject(
new errors.SystemError('MySQL check failed.')
));
let confirmPromise = ctx.ui.allowPrompt ?
ctx.ui.confirm(chalk.blue('Continue anyway?'), false) :
Promise.resolve({yes: false});

return confirmPromise.then(answer => answer.yes || Promise.reject(
new errors.SystemError('MySQL check failed.')
));
});
}
}];

0 comments on commit 1641676

Please sign in to comment.