-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,11 @@ | |
|
||
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 os from 'os'; | ||
import * as path from 'path'; | ||
import { Ditamap } from '../../ditamap/ditamap'; | ||
import { Docs } from '../../docs'; | ||
import { events, mergeDeep } from '../../utils'; | ||
|
@@ -34,15 +36,29 @@ 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some error messaging? For example, I can do |
||
const pJsonPath = path.join(process.cwd(), 'package.json'); | ||
if (await fs.fileExists(pJsonPath)) { | ||
const packageJson = await fs.readJson(pJsonPath); | ||
pluginNames = [getString(packageJson, 'name')]; | ||
} else { | ||
throw new SfdxError( | ||
'No package.json found in current working directory. Please cd into a directory that contains a valid oclif plugin' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
); | ||
} | ||
} else { | ||
pluginNames = this.flags.plugins; | ||
} | ||
|
||
const plugins = pluginNames | ||
.map(plugin => plugin.trim()) | ||
.map(name => { | ||
let pluginName = name; | ||
|
@@ -57,7 +73,7 @@ export default class CommandReferenceGenerate extends SfdxCommand { | |
} | ||
return pluginName; | ||
}); | ||
|
||
this.ux.log(`Generating command refernce for the following plugins:${plugins.map(name => `${os.EOL} - ${name}`)}`); | ||
Ditamap.outputDir = this.flags.outputdir; | ||
|
||
Ditamap.cliVersion = this.config.version.replace(/-[0-9a-zA-Z]+$/, ''); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still sounds weird to me because this is a plugin list, and you are saying it defaults to the current working directory which is a file path, not a plugin. Maybe
defaults to the oclif plugin in the current working directory