UNPKG

moleculer-repl

Version:
58 lines (49 loc) 1.46 kB
"use strict"; const util = require("util"); /** * Command logic * @param {import("moleculer").ServiceBroker} broker Moleculer's Service Broker * @param {Object} args Parsed arguments */ async function handler(broker, args) { console.log( util.inspect(process.env, { showHidden: false, depth: 4, colors: true }) ); } /** * Command option declarations * @param {import("commander").Command} program Commander * @param {import("moleculer").ServiceBroker} broker Moleculer's Service Broker * @param {Function} cmdHandler Command handler */ function declaration(program, broker, cmdHandler) { program .command("env") .description("List of environment variables") .hook("preAction", (thisCommand) => { // Command without params. Keep for consistency sake let parsedArgs = {}; const rawCommand = thisCommand.parent.rawArgs.slice(2).join(" "); // Set the params thisCommand.params = { options: parsedArgs, rawCommand, }; // Clear the parsed values for next execution thisCommand._optionValues = {}; }) .action(async function () { // Get the params await cmdHandler(broker, this.params); }); } /** * Register the command * * @param {import("commander").Command} program Commander * @param {import("moleculer").ServiceBroker} broker Moleculer's Service Broker */ function register(program, broker) { declaration(program, broker, handler); } module.exports = { register, declaration, handler };