Home

CLI Utilities

The CLI utilities provide simple command-line argument parsing functionality for Node.js applications.

Installation

Import the utilities from the kempo-server package:

import { getArgs } from 'kempo-server/utils/cli';

getArgs(mapping, argv)

Parses command-line arguments into a key-value object.

Parameters

Returns

An object where keys are argument names and values are parsed argument values.

Features

Examples

Basic Usage

node app.js --port 8080 --host localhost --verbose
const args = getArgs();
// Result: { port: '8080', host: 'localhost', verbose: true }

With Short Flag Mapping

node app.js -p 8080 -h localhost -v
const args = getArgs({
  p: 'port',
  h: 'host',
  v: 'verbose'
});
// Result: { port: '8080', host: 'localhost', verbose: true }

Equals-Separated Values

node app.js --port=8080 --enabled=true --disabled=false --name=John
const args = getArgs();
// Result: { port: '8080', enabled: true, disabled: false, name: 'John' }

Mixed Formats

node app.js --port=8080 -h localhost --verbose --config=prod.json
const args = getArgs({ h: 'host' });
// Result: { port: '8080', host: 'localhost', verbose: true, config: 'prod.json' }

Values with Equals Signs

node app.js --url=https://example.com?param=value
const args = getArgs();
// Result: { url: 'https://example.com?param=value' }

Other Functions

The CLI utilities module also exports other functions for running child processes and prompting users:

c:\Users\dusti\dev\kempo-server\docs\cli-utils.html