felixSchl/neodoc

Expose running from a spec (w/o parsing the spec)

felixSchl opened this issue · 2 comments

This would allow users to use the argv parser on it's own by providing a spec.
The spec could then even be expanded to have custom error messages etc.
This could also allow people to parse the spec using neodoc and then run alterations on top and pass it back to neodoc for parsing the argv against it.

work is tracked on: feature/parse-spec

  • Implement a fromForeign function to read a spec
  • alter neodoc.run to take either a spec object or a string: neodoc.run(spec | string, options). This will be a FFI/Foreign nightmare, but is the mast javascript friendly approach. Maybe the routing could happen on JS level in lib/docop.js.

This could also drastically improve performance if we cached the spec as json as the json parser will likely be an order of magnitude faster than the specparser. Currently at least.

Edit: After trying this out I found that parsing the examples/uglifyjs.js neodoc spec currently costs around 130ms. Parsing the spec from JSON costs 4ms, so it's more than 30 times faster and could be well worth the effort. The question is just if neodoc should do the caching IO transparently or approach it from a traditional compile-step angle.

This has been merged into development and will be available in the next release - 2d712ba