Skip to content

plugin

Generated reference page for the plugin function export.

Signatures

ts
function plugin(hooks: CLIPluginHooks, name?: string): CLIPlugin;
ParameterTypeDescription
hooksCLIPluginHooksLifecycle hooks to register.
namestring | undefinedOptional plugin name for diagnostics.

Members

Members

plugin

Create a CLI plugin from lifecycle hooks.

ts
(hooks: CLIPluginHooks, name?: string): CLIPlugin;

Examples

ts
import { cli, command, plugin } from '@kjanat/dreamcli';

const deploy = command('deploy').action(({ out }) => {
  out.log('deploying');
});

const trace = plugin(
  {
    beforeParse: ({ argv, out }) => {
      out.info(`argv: ${argv.join(' ')}`);
    },
    afterResolve: ({ flags, args }) => {
      console.log({ flags, args });
    },
  },
  'trace',
);

cli('mycli').plugin(trace).command(deploy).run();

See Also

Released under the MIT License.