UNPKG

@sap/cli-core

Version:

Command-Line Interface (CLI) Core Module

19 lines (18 loc) 1.07 kB
import { kebabCase } from "lodash-es"; import { set as setConfig } from "../../config/index.js"; import { getBooleanOption, parseOption } from "./utils.js"; import { OPTION_VERBOSE } from "../../constants.js"; import { get as getLogger } from "../../logger/index.js"; export const create = (handlerArgs) => async () => async (...args) => { const { debug } = getLogger("commands.handler.parseArguments"); const command = args[args.length - 1].name(); const options = Object.entries(args[args.length - 2]) .map((o) => [o[0], parseOption(o[1])]) .reduce((prev, curr) => ({ ...prev, [kebabCase(curr[0])]: curr[1] }), {}); const commandArgs = handlerArgs ? handlerArgs.reduce((p, c, i) => ({ ...p, [c.argument]: args[i] }), {}) : {}; const verbose = getBooleanOption(options[OPTION_VERBOSE.longName]); debug("setting command: %s, options: %s, arguments: %s, verbose: %s", command, JSON.stringify(options), JSON.stringify(commandArgs), verbose); setConfig({ command, options, arguments: commandArgs, verbose }); };