packages/cli: add --check and --yes flags to plugin:diff
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
import chalk from 'chalk';
|
||||
import inquirer from 'inquirer';
|
||||
import { Command } from 'commander';
|
||||
import { readTemplateFiles } from './read';
|
||||
import { handlers, handleAllFiles } from './handlers';
|
||||
import { PromptFunc } from './types';
|
||||
@@ -49,7 +50,23 @@ const inquirerPromptFunc: PromptFunc = async msg => {
|
||||
return result;
|
||||
};
|
||||
|
||||
export default async () => {
|
||||
const templateFiles = await readTemplateFiles('default-plugin');
|
||||
await handleAllFiles(fileHandlers, templateFiles, inquirerPromptFunc);
|
||||
const checkPromptFunc: PromptFunc = async msg => {
|
||||
throw new Error(`Check failed, the following change was needed: ${msg}`);
|
||||
};
|
||||
const yesPromptFunc: PromptFunc = async msg => {
|
||||
console.log(`Accepting: "${msg}"`);
|
||||
return true;
|
||||
};
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
let promptFunc = inquirerPromptFunc;
|
||||
|
||||
if (cmd.check) {
|
||||
promptFunc = checkPromptFunc;
|
||||
} else if (cmd.yes) {
|
||||
promptFunc = yesPromptFunc;
|
||||
}
|
||||
|
||||
const templateFiles = await readTemplateFiles('default-plugin');
|
||||
await handleAllFiles(fileHandlers, templateFiles, promptFunc);
|
||||
};
|
||||
|
||||
@@ -64,6 +64,8 @@ const main = (argv: string[]) => {
|
||||
|
||||
program
|
||||
.command('plugin:diff')
|
||||
.option('--check', 'Fail if changes are required')
|
||||
.option('--yes', 'Apply all changes')
|
||||
.description('Diff an existing plugin with the creation template')
|
||||
.action(actionHandler(() => require('commands/plugin/diff')));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user