Skip to content

neoncitylights/cli-help-parser

Repository files navigation

CLI help parser for FIG specs

License: MIT GitHub deployments codecov

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.

Setup

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

Documentation

Auto-generated API documentation is available.

Performance

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:

  • TypeScript version: 4.6.2
  • Node.js: 17.7.2
  • Machine:
    • Model: MacBook Pro 2015
    • OS version: macOS Monterey 12.2.1
    • CPU: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    • Memory: 16 GB 1600 MHz DDR3

The timing was tested via console.time() and console.timeEnd(). 12

Post-processing

After parsing every option/subcommand, it post-processes the description using some basic heuristics to find out more information:

Deprecated

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.

Argument templates

  • Folders: If the sentence contains the keywords directory, and the option accepts an argument, it will add "folders" to the template property.
  • Filepaths: If the sentence contains the keywords filename, and the option accepts an argument, it will add "filepaths" to the template property.

License

This repository is released under the MIT License.

Footnotes

  1. https://console.spec.whatwg.org/#time

  2. https://console.spec.whatwg.org/#timeend

About

tool to parse a CLI's help manual into a machine-readable AST

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published