diff --git a/packages/cli/src/commands/plugin/diff/index.ts b/packages/cli/src/commands/plugin/diff/index.ts index 87e8628ee4..116ba9e633 100644 --- a/packages/cli/src/commands/plugin/diff/index.ts +++ b/packages/cli/src/commands/plugin/diff/index.ts @@ -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); }; diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index bdb0efff8f..6c6aec3776 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -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')));