25 lines
797 B
JavaScript
25 lines
797 B
JavaScript
import { importGlobalSilent } from 'import-global';
|
|
|
|
/**
|
|
* Dynamically load and register CLI options from plugins.
|
|
*
|
|
* @param {import('yargs').Argv} yargsInstance - The yargs instance to extend.
|
|
* @param {string[]} plugins - Array of plugin module names.
|
|
* @returns {Promise<void>}
|
|
*/
|
|
export async function registerPluginOptions(yargsInstance, plugins) {
|
|
for (const pluginName of plugins) {
|
|
try {
|
|
// Dynamically import the plugin
|
|
const plugin = await importGlobalSilent(pluginName);
|
|
// If the plugin exports a function to get CLI options, merge them
|
|
if (plugin && typeof plugin.getCliOptions === 'function') {
|
|
const options = plugin.getCliOptions();
|
|
yargsInstance.options(options);
|
|
}
|
|
} catch {
|
|
// Swallow this silent
|
|
}
|
|
}
|
|
}
|