* refactor(cli): defer default value applying * Allow plugins to override default options * Move "defaultOptions" to top level of plugin * Simplify implementation * Attach plugin name * Add pluginOptions to cli help * Update snapshots * Code review (immutable style) * Add test for help output * Use snapshot test, fix Object.assign * Refactor to immutable style * Add test case for automatic plugin resolution * Add tests for applying and overriding default opts * Remove "since" option * Only set defaults for CLI args when no pluginDefaults are present * Revert workaround, rebase to #4045 * Add basic documentation for `options` and `defaultOptions`
20 lines
425 B
JavaScript
20 lines
425 B
JavaScript
"use strict";
|
|
|
|
function getPlugin(options) {
|
|
const astFormat = options.astFormat;
|
|
|
|
if (!astFormat) {
|
|
throw new Error("getPlugin() requires astFormat to be set");
|
|
}
|
|
const printerPlugin = options.plugins.find(
|
|
plugin => plugin.printers[astFormat]
|
|
);
|
|
if (!printerPlugin) {
|
|
throw new Error(`Couldn't find plugin for AST format "${astFormat}"`);
|
|
}
|
|
|
|
return printerPlugin;
|
|
}
|
|
|
|
module.exports = getPlugin;
|