packages/cli: add --check and --yes flags to plugin:diff

This commit is contained in:
Patrik Oldsberg
2020-05-03 14:25:36 +02:00
parent 7d02e1d15c
commit 56ff5d7d97
2 changed files with 22 additions and 3 deletions
+20 -3
View File
@@ -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);
};
+2
View File
@@ -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')));