CLI List Parser

1.0.0 · active · verified Wed Apr 22

cli-list is a utility package designed to parse command-line argument lists, typically sourced from `process.argv`, into a structured array of arrays. It specializes in breaking down a single array of arguments, where items might be comma-separated, into sub-arrays at each comma delimiter. This maintains the "argv style" of the sub-arrays, making them suitable for direct consumption by other command-line argument parsers like `minimist`. The current stable version is 1.0.0, which was released recently and updated the codebase to modern JavaScript standards while strictly enforcing a minimum Node.js engine requirement of 18.0.0. The package has a focused scope, providing a clear solution for preprocessing CLI arguments that utilize comma-separated values, acting as an essential parsing layer before more complex option handling.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to parse a raw `process.argv` style array with `cli-list` and then further process each resulting sub-array using `minimist`.

import list from 'cli-list';
import minimist from 'minimist'; // minimist needs to be installed via `npm install minimist`

// Simulate process.argv.slice(2) for a test case
// In a real CLI, you'd use: const args = process.argv.slice(2);
const rawCliArgs = ['foo', '--bar,', 'baz', '--qux', 'oof,value'];

console.log('Original CLI arguments:', rawCliArgs);

// Split the arguments into sub-arrays based on commas
const parsedLists = list(rawCliArgs);
console.log('cli-list parsed lists:', parsedLists);
// Expected: [['foo', '--bar'], ['baz'], ['--qux', 'oof'], ['value']]

// Process each sub-list using minimist
const opts = parsedLists.map(item => minimist(item));
console.log('Minimist parsed options for each list:', opts);
/*
Expected Output (opts):
[
  { _: [ 'foo' ], bar: true },
  { _: [ 'baz' ] },
  { _: [ 'oof' ], qux: true },
  { _: [ 'value' ] }
]
*/

view raw JSON →