Skip to content

Commit 57a66b2

Browse files
authored
feat: default to current working directory when no plugins are provided (#15)
* feat: default to current working directory when no plugins are provided * chore: code review * chore: code review
1 parent 5a53571 commit 57a66b2

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

messages/main.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"commandDescription": "generate the command reference guide located",
3-
"pluginFlagDescription": "comma separated list of plugin names to be part of the generation",
3+
"pluginFlagDescription": "comma separated list of plugin names to be part of the generation. Defaults to the oclif plugin in the current working directory",
44
"hiddenFlagDescription": "show hidden commands",
55
"outputdirFlagDescription": "output directory to put generated files",
66
"erroronwarningFlagDescription": "fail the command if there are any warnings"

src/commands/commandreference/generate.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
import { IPlugin } from '@oclif/config';
99
import { flags, SfdxCommand } from '@salesforce/command';
10-
import { Messages, SfdxError } from '@salesforce/core';
11-
import { AnyJson, Dictionary, ensure, JsonMap } from '@salesforce/ts-types';
10+
import { fs, Messages, SfdxError } from '@salesforce/core';
11+
import { AnyJson, Dictionary, ensure, getString, JsonMap } from '@salesforce/ts-types';
1212
import chalk = require('chalk');
13+
import * as os from 'os';
14+
import * as path from 'path';
1315
import { Ditamap } from '../../ditamap/ditamap';
1416
import { Docs } from '../../docs';
1517
import { events, mergeDeep } from '../../utils';
@@ -34,15 +36,29 @@ export default class CommandReferenceGenerate extends SfdxCommand {
3436
}),
3537
plugins: flags.array({
3638
char: 'p',
37-
description: messages.getMessage('pluginFlagDescription'),
38-
required: true
39+
description: messages.getMessage('pluginFlagDescription')
3940
}),
4041
hidden: flags.boolean({ description: messages.getMessage('hiddenFlagDescription') }),
4142
erroronwarnings: flags.boolean({ description: messages.getMessage('erroronwarningFlagDescription') })
4243
};
4344

4445
public async run(): Promise<AnyJson> {
45-
const plugins = this.flags.plugins
46+
let pluginNames: string[];
47+
if (!this.flags.plugins) {
48+
const pJsonPath = path.join(process.cwd(), 'package.json');
49+
if (await fs.fileExists(pJsonPath)) {
50+
const packageJson = await fs.readJson(pJsonPath);
51+
pluginNames = [getString(packageJson, 'name')];
52+
} else {
53+
throw new SfdxError(
54+
'No plugins provided. Provide the \'--plugins\' flag or cd into a directory that contains a valid oclif plugin.'
55+
);
56+
}
57+
} else {
58+
pluginNames = this.flags.plugins;
59+
}
60+
61+
const plugins = pluginNames
4662
.map(plugin => plugin.trim())
4763
.map(name => {
4864
let pluginName = name;
@@ -57,7 +73,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
5773
}
5874
return pluginName;
5975
});
60-
76+
this.ux.log(`Generating command refernce for the following plugins:${plugins.map(name => `${os.EOL} - ${name}`)}`);
6177
Ditamap.outputDir = this.flags.outputdir;
6278

6379
Ditamap.cliVersion = this.config.version.replace(/-[0-9a-zA-Z]+$/, '');

0 commit comments

Comments
 (0)