Skip to content

Commit 1f77407

Browse files
acburdineErisDS
authored andcommitted
fix(help): add onlyOptions argument to configureOptions
1 parent 61fc7c0 commit 1f77407

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

lib/command.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,21 @@ class Command {
132132
* @method configureOptions
133133
* @public
134134
*/
135-
static configureOptions(commandName, yargs) {
135+
static configureOptions(commandName, yargs, extensions, onlyOptions) {
136+
each(this.options || {}, (option, optionName) => {
137+
yargs = yargs.option(kebabCase(optionName), option);
138+
});
139+
140+
if (onlyOptions) {
141+
return yargs;
142+
}
143+
136144
if (this.longDescription) {
137145
yargs.usage(this.longDescription);
138146
}
139147

140148
yargs.epilogue('For more information, see our docs at https://docs.ghost.org/docs/ghost-cli');
141149

142-
each(this.options || {}, (option, optionName) => {
143-
yargs = yargs.option(kebabCase(optionName), option);
144-
});
145-
146150
return yargs;
147151
}
148152

lib/commands/install.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const SetupCommand = require('./setup');
1919
class InstallCommand extends Command {
2020
static configureOptions(commandName, yargs, extensions) {
2121
yargs = super.configureOptions(commandName, yargs, extensions);
22-
return SetupCommand.configureOptions('setup', yargs, extensions);
22+
return SetupCommand.configureOptions('setup', yargs, extensions, true);
2323
}
2424

2525
run(argv) {

lib/commands/setup.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const StartCommand = require('./start');
1313
const ConfigCommand = require('./config');
1414

1515
class SetupCommand extends Command {
16-
static configureOptions(commandName, yargs, extensions) {
16+
static configureOptions(commandName, yargs, extensions, onlyOptions) {
1717
extensions.forEach((extension) => {
1818
let options = get(extension, 'config.options.setup', false);
1919
if (!options) {
@@ -23,9 +23,9 @@ class SetupCommand extends Command {
2323
Object.assign(this.options, omit(options, Object.keys(this.options)));
2424
});
2525

26-
yargs = super.configureOptions(commandName, yargs, extensions);
27-
yargs = ConfigCommand.configureOptions('config', yargs, extensions);
28-
yargs = StartCommand.configureOptions('start', yargs, extensions);
26+
yargs = super.configureOptions(commandName, yargs, extensions, onlyOptions);
27+
yargs = ConfigCommand.configureOptions('config', yargs, extensions, true);
28+
yargs = StartCommand.configureOptions('start', yargs, extensions, true);
2929
}
3030

3131
constructor(ui, system) {

test/unit/command-spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ describe('Unit: Command', function () {
135135
expect(optionStub.args[1][1]).to.deep.equal({alias: 'c', description: 'test kebab-case'});
136136
expect(result).to.deep.equal(yargsStub);
137137
});
138+
139+
it('skips adding epilogue and usage if onlyOptions is true', function () {
140+
let TestCommand = class extends Command {}
141+
TestCommand.options = {
142+
flag: {
143+
alias: 'f',
144+
description: 'a flag'
145+
}
146+
};
147+
TestCommand.longDescription = 'LONG DESCRIPTION';
148+
let yargsStub = {};
149+
let optionStub = sinon.stub().returns(yargsStub);
150+
let epilogueStub = sinon.stub();
151+
let usageStub = sinon.stub();
152+
yargsStub.option = optionStub;
153+
yargsStub.epilogue = epilogueStub;
154+
155+
let result = TestCommand.configureOptions('test', yargsStub, [], true);
156+
157+
expect(epilogueStub.called).to.be.false;
158+
expect(usageStub.called).to.be.false;
159+
expect(optionStub.calledOnce).to.be.true;
160+
expect(optionStub.args[0]).to.deep.equal(['flag', {alias: 'f', description: 'a flag'}]);
161+
expect(result).to.deep.equal(yargsStub);
162+
});
138163
});
139164

140165
describe('_run', function () {

0 commit comments

Comments
 (0)