Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: default to current working directory when no plugins are provided #15

Merged
merged 3 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion messages/main.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"commandDescription": "generate the command reference guide located",
"pluginFlagDescription": "comma separated list of plugin names to be part of the generation",
"pluginFlagDescription": "comma separated list of plugin names to be part of the generation. Defaults to current working directory.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. - defaults to the plugin in the current working directory, if there is one? See my note below.

"hiddenFlagDescription": "show hidden commands",
"outputdirFlagDescription": "output directory to put generated files",
"erroronwarningFlagDescription": "fail the command if there are any warnings"
Expand Down
19 changes: 14 additions & 5 deletions src/commands/commandreference/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import { IPlugin } from '@oclif/config';
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxError } from '@salesforce/core';
import { AnyJson, Dictionary, ensure, JsonMap } from '@salesforce/ts-types';
import { fs, Messages, SfdxError } from '@salesforce/core';
import { AnyJson, Dictionary, ensure, getString, JsonMap } from '@salesforce/ts-types';
import chalk = require('chalk');
import * as path from 'path';
import { Ditamap } from '../../ditamap/ditamap';
import { Docs } from '../../docs';
import { events, mergeDeep } from '../../utils';
Expand All @@ -34,15 +35,23 @@ export default class CommandReferenceGenerate extends SfdxCommand {
}),
plugins: flags.array({
char: 'p',
description: messages.getMessage('pluginFlagDescription'),
required: true
description: messages.getMessage('pluginFlagDescription')
}),
hidden: flags.boolean({ description: messages.getMessage('hiddenFlagDescription') }),
erroronwarnings: flags.boolean({ description: messages.getMessage('erroronwarningFlagDescription') })
};

public async run(): Promise<AnyJson> {
const plugins = this.flags.plugins
let pluginNames: string[];
if (!this.flags.plugins) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some error messaging? For example, I can do sfdx plugins:install command-reference then sfdx commandreference:generate in any directory I want.

const pJsonPath = path.join(process.cwd(), 'package.json');
const packageJson = await fs.readJson(pJsonPath);
pluginNames = [getString(packageJson, 'name')];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we log to the user what plugin we are going to generate reference for?

} else {
pluginNames = this.flags.plugins;
}

const plugins = pluginNames
.map(plugin => plugin.trim())
.map(name => {
let pluginName = name;
Expand Down