Skip to content

Commit

Permalink
fix(install): rename force flag to 'check-empty' (#1237)
Browse files Browse the repository at this point in the history
closes #1218
  • Loading branch information
acburdine authored Jun 28, 2020
1 parent 2223062 commit 6281eaa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
9 changes: 5 additions & 4 deletions lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InstallCommand extends Command {
let version = argv.version ? `${argv.version}` : null;

// Check if the directory is empty
if (!dirIsEmpty(process.cwd()) && !argv.force) {
if (!dirIsEmpty(process.cwd()) && argv['check-empty']) {
return Promise.reject(new errors.SystemError('Current directory is not empty, Ghost cannot be installed here.'));
}

Expand Down Expand Up @@ -170,9 +170,10 @@ InstallCommand.options = {
description: 'Path to a Ghost export file to import after setup',
type: 'string'
},
force: {
description: 'Force install in non-empty directory',
type: 'boolean'
'check-empty': {
description: 'Check for empty directory before installing',
type: 'boolean',
default: true
}
};
InstallCommand.runPreChecks = true;
Expand Down
30 changes: 15 additions & 15 deletions test/unit/commands/install-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Unit: Commands > Install', function () {
});
const testInstance = new InstallCommand({}, {});

return testInstance.run({version: '1.0.0'}).then(() => {
return testInstance.run({version: '1.0.0', 'check-empty': true}).then(() => {
expect(false, 'error should have been thrown').to.be.true;
}).catch((error) => {
expect(error).to.be.an.instanceof(errors.SystemError);
Expand Down Expand Up @@ -88,14 +88,14 @@ describe('Unit: Commands > Install', function () {
const testInstance = new InstallCommand({listr: listrStub}, {cliVersion: '1.0.0', setEnvironment: setEnvironmentStub});
const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves();

return testInstance.run({version: 'local', zip: '', v1: true}).then(() => {
return testInstance.run({version: 'local', zip: '', v1: true, 'check-empty': true}).then(() => {
expect(false, 'run should have rejected').to.be.true;
}).catch(() => {
expect(dirEmptyStub.calledOnce).to.be.true;
expect(runCommandStub.calledOnce).to.be.true;
expect(listrStub.calledOnce).to.be.true;
expect(listrStub.args[0][1]).to.deep.equal({
argv: {version: null, zip: '', v1: true},
argv: {version: null, zip: '', v1: true, 'check-empty': true},
cliVersion: '1.0.0'
});
expect(setEnvironmentStub.calledOnce).to.be.true;
Expand All @@ -116,14 +116,14 @@ describe('Unit: Commands > Install', function () {
const testInstance = new InstallCommand({listr: listrStub}, {cliVersion: '1.0.0', setEnvironment: setEnvironmentStub});
const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves();

return testInstance.run({version: '1.5.0', local: true, zip: '', v1: false}).then(() => {
return testInstance.run({version: '1.5.0', local: true, zip: '', v1: false, 'check-empty': true}).then(() => {
expect(false, 'run should have rejected').to.be.true;
}).catch(() => {
expect(dirEmptyStub.calledOnce).to.be.true;
expect(runCommandStub.calledOnce).to.be.true;
expect(listrStub.calledOnce).to.be.true;
expect(listrStub.args[0][1]).to.deep.equal({
argv: {version: '1.5.0', zip: '', v1: false, local: true},
argv: {version: '1.5.0', zip: '', v1: false, local: true, 'check-empty': true},
cliVersion: '1.0.0'
});
expect(setEnvironmentStub.calledOnce).to.be.true;
Expand All @@ -144,14 +144,14 @@ describe('Unit: Commands > Install', function () {
const testInstance = new InstallCommand({listr: listrStub}, {cliVersion: '1.0.0', setEnvironment: setEnvironmentStub});
const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves();

return testInstance.run({version: '1.5.0', zip: '', v1: false, _: ['install', 'local']}).then(() => {
return testInstance.run({version: '1.5.0', zip: '', v1: false, _: ['install', 'local'], 'check-empty': true}).then(() => {
expect(false, 'run should have rejected').to.be.true;
}).catch(() => {
expect(dirEmptyStub.calledOnce).to.be.true;
expect(runCommandStub.calledOnce).to.be.true;
expect(listrStub.calledOnce).to.be.true;
expect(listrStub.args[0][1]).to.deep.equal({
argv: {version: '1.5.0', zip: '', v1: false, _: ['install', 'local']},
argv: {version: '1.5.0', zip: '', v1: false, _: ['install', 'local'], 'check-empty': true},
cliVersion: '1.0.0'
});
expect(setEnvironmentStub.calledOnce).to.be.true;
Expand All @@ -172,14 +172,14 @@ describe('Unit: Commands > Install', function () {
const testInstance = new InstallCommand({listr: listrStub}, {cliVersion: '1.0.0', setEnvironment: setEnvironmentStub});
const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves();

return testInstance.run({version: 2, zip: '', v1: false, _: ['install', 'local']}).then(() => {
return testInstance.run({version: 2, zip: '', v1: false, _: ['install', 'local'], 'check-empty': true}).then(() => {
expect(false, 'run should have rejected').to.be.true;
}).catch(() => {
expect(dirEmptyStub.calledOnce).to.be.true;
expect(runCommandStub.calledOnce).to.be.true;
expect(listrStub.calledOnce).to.be.true;
expect(listrStub.args[0][1]).to.deep.equal({
argv: {version: '2', zip: '', v1: false, _: ['install', 'local']},
argv: {version: '2', zip: '', v1: false, _: ['install', 'local'], 'check-empty': true},
cliVersion: '1.0.0'
});
expect(setEnvironmentStub.calledOnce).to.be.true;
Expand All @@ -204,7 +204,7 @@ describe('Unit: Commands > Install', function () {
const linkStub = sinon.stub(testInstance, 'link').resolves();
const casperStub = sinon.stub(testInstance, 'casper').resolves();

return testInstance.run({version: '1.0.0', setup: false}).then(() => {
return testInstance.run({version: '1.0.0', setup: false, 'check-empty': true}).then(() => {
expect(dirEmptyStub.calledOnce).to.be.true;
expect(listrStub.calledTwice).to.be.true;
expect(yarnInstallStub.calledOnce).to.be.true;
Expand All @@ -228,20 +228,20 @@ describe('Unit: Commands > Install', function () {
const testInstance = new InstallCommand({listr: listrStub}, {cliVersion: '1.0.0', setEnvironment: setEnvironmentStub});
const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves();

return testInstance.run({version: 'local', setup: true, zip: ''}).then(() => {
return testInstance.run({version: 'local', setup: true, zip: '', 'check-empty': true}).then(() => {
expect(dirEmptyStub.calledOnce).to.be.true;
expect(listrStub.calledOnce).to.be.true;
expect(setEnvironmentStub.calledOnce).to.be.true;
expect(setEnvironmentStub.calledWithExactly(true, true));
expect(runCommandStub.calledTwice).to.be.true;
expect(runCommandStub.calledWithExactly(
{SetupCommand: true},
{version: 'local', local: true, zip: ''}
{version: 'local', local: true, zip: '', 'check-empty': true}
));
});
});

it('allows running in non-empty directory if --force is passed', function () {
it('allows running in non-empty directory if --no-check-empty is passed', function () {
const dirEmptyStub = sinon.stub().returns(false);
const listrStub = sinon.stub().resolves();
const setEnvironmentStub = sinon.stub();
Expand All @@ -253,15 +253,15 @@ describe('Unit: Commands > Install', function () {
const testInstance = new InstallCommand({listr: listrStub}, {cliVersion: '1.0.0', setEnvironment: setEnvironmentStub});
const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves();

return testInstance.run({version: 'local', setup: true, zip: '', force: true}).then(() => {
return testInstance.run({version: 'local', setup: true, zip: '', 'check-empty': false}).then(() => {
expect(dirEmptyStub.calledOnce).to.be.true;
expect(listrStub.calledOnce).to.be.true;
expect(setEnvironmentStub.calledOnce).to.be.true;
expect(setEnvironmentStub.calledWithExactly(true, true));
expect(runCommandStub.calledTwice).to.be.true;
expect(runCommandStub.calledWithExactly(
{SetupCommand: true},
{version: 'local', local: true, zip: ''}
{version: 'local', local: true, zip: '', 'check-empty': false}
));
});
});
Expand Down

0 comments on commit 6281eaa

Please sign in to comment.