Parse CLI Help Output

2.0.0 · active · verified Wed Apr 22

parse-help is a JavaScript utility for programmatically parsing the help output of command-line interfaces, extracting structured information about their flags, options, and aliases. It provides a structured object representation of CLI options, making it easier to analyze or process them within other tools. The current stable version is 2.0.0. The package is maintained by Sindre Sorhus, known for a high volume of small, focused utility packages, typically implying a stable but not necessarily rapid release cadence unless new features or breaking changes warrant it. A key differentiator is its focus specifically on parsing *help output* rather than building a CLI from scratch or parsing `argv` directly, making it useful for introspection or documentation generation from existing CLIs.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use `parseHelp` to process a sample CLI help string and output the structured flags and aliases.

import parseHelp from 'parse-help';

const helpOutput = `
	Usage
	  $ my-cli <command> [options]

	Options
	  -v, --verbose    Enable verbose logging
	  --config <path>  Specify a configuration file (default: config.json)
	  -h, --help       Show help information

	Examples
	  $ my-cli start
	  $ my-cli build --config custom.json
`;

const parsed = parseHelp(helpOutput);

console.log('Parsed Flags:', JSON.stringify(parsed.flags, null, 2));
console.log('Parsed Aliases:', JSON.stringify(parsed.aliases, null, 2));

/*
Output would be:
Parsed Flags: {
  "verbose": {
    "alias": "v",
    "description": "Enable verbose logging"
  },
  "config": {
    "description": "Specify a configuration file (default: config.json)"
  },
  "help": {
    "alias": "h",
    "description": "Show help information"
  }
}
Parsed Aliases: {
  "v": "verbose",
  "h": "help"
}
*/

view raw JSON →