UNPKG

reactium

Version:

A CLI for creating Reactium / Actinium projects.

74 lines (66 loc) 2.03 kB
/** * ----------------------------------------------------------------------------- * Imports * ----------------------------------------------------------------------------- */ import actions from './actions.js'; const { message, op, generator, Spinner, chalk } = arcli; /** * NAME String * @description Constant defined as the command name. Value passed to the commander.command() function. * @example $ arcli list * @see https://www.npmjs.com/package/commander#command-specific-options * @since 2.0.0 */ export const NAME = 'list'; /** * DESC String * @description Constant defined as the command description. Value passed to * the commander.desc() function. This string is also used in the --help flag output. * @see https://www.npmjs.com/package/commander#automated---help * @since 2.0.0 */ const DESC = 'List arcli packages.'; /** * CANCELED String * @description Message sent when the command is canceled * @since 2.0.0 */ const CANCELED = 'List canceled!'; /** * HELP Function * @description Function called in the commander.on('--help', callback) callback. * @see https://www.npmjs.com/package/commander#automated---help * @since 2.0.0 */ const HELP = () => console.log(` Example: $ arcli list `); /** * ACTION Function * @description Function used as the commander.action() callback. * @see https://www.npmjs.com/package/commander * @param opt Object The commander options passed into the function. * @param props Object The CLI props passed from the calling class `orcli.js`. * @since 2.0.0 */ const ACTION = ({ props }) => { let params = {}; return generator({ actions: actions(Spinner), params, props, }).catch(err => message(op.get(err, 'message', CANCELED))); }; /** * COMMAND Function * @description Function that executes program.command() */ export const COMMAND = ({ program, props }) => program .command(NAME) .description(DESC) .action(opt => ACTION({ opt, props })) .on('--help', HELP);