This library provides a parser that, given a CLI help manual, generates some scaffolding for machine-readable Fig specs.
I originally created this repository to help add the webpack spec to Fig.
Currently, this library is slightly hardcoded to just recognize webpack's help manual, but I may update it in the future to make this parser more generic.
Running the NPM script will generate an options.json
file (intentionally git-ignored in .gitignore
).
gh repo clone neoncitylights/cli-help-parser
npm install
npm run generate
Auto-generated API documentation is available.
This script will usually take longer on the first run, and faster on subsequent runs.
With some informal benchmarking, this script can take around 30 milliseconds on sebsequent runs from parsing all of 957 options of the webpack
CLI tool, with only the native macOS terminal open. This roughly tracks to approximately 36.57 μs (microseconds) per line.
The script+benchmark was ran under the following environment:
The timing was tested via console.time()
and console.timeEnd()
. ^console-time
After parsing every option/subcommand, it post-processes the description using some basic heuristics to find out more information:
If the sentence contains the keyword deprecated
, it will mark it as deprecated via deprecated: true
.
It will also look to see if there is any inline code by checking for inline code delimiters, and use that as the insertValue
.
directory
, and the option accepts an argument, it will add "folders"
to the template
property.filename
, and the option accepts an argument, it will add "filepaths"
to the template
property.This repository is released under the MIT License.
Generated using TypeDoc