GithubHelp home page GithubHelp logo

linterhub / usage-parser Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 3.0 186 KB

Usage parser

Home Page: https://github.com/linterhub/usage-parser

License: MIT License

TypeScript 100.00%
cli command options argument args parser help flags

usage-parser's People

Contributors

ifedchankau avatar itekaf avatar xferra avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

usage-parser's Issues

Add config validation

Please, add validation of configuration, which should have:

  • validation of config correctness
  • empty values filling with defaults

Add parsing of "args" prefix by examples

Sometimes, in options section it is no information what can be interpreted that option is not flag. But, in examples there is so.

Example:

  Options:
    --plugin          Include third-party plugins [Can be set multiple times]

  Examples:
    $ xo --plugin=html --extension=html

Please, add parsing of "args" prefix by examples.

Delete default value from description

Now, after parsing an argument, default value in it description isn't deleted. Please, make so, that default value will be deleted from description.

Add travis configuration

Please, add travis configuration.

Config must be include following command:

  • npm run test
  • linting

Add other patterns of default value of argument

Now, in parser using only one pattern of default value of argument:
/\[default: (.*?)]/

So, default value will be parsed only if it looks like [default: 70].

Please, add other patterns.

Error in section parsing

I find next errors:

  • sections Usage and Examples parsing only one time (only first)
  • section Examples isn't parsing when it CAPITALIZED

Please, fix it.

Refactoring of tests

Please, do refactoring of tests, because parts of code in test/config/test.js, test/sections/test.js, test/result/test.js are the same.

Also, please, do refactoring of tests filenames (folder files #52).

Refactoring of junk code

Next solutions isn't good:

  • function handle of handle.js file
const context = require('./template/context.js');
context.options = [];
  • function templatizer of templatizer.js file
const argumentsTemplate = JSON.parse(fs.readFileSync('./src/template/args.json'));
argumentsTemplate.definitions.arguments.properties = {};

It it necessary, because javascript filling empty templates, and for each next iteration of parser, js using this filled templates. Please, find best solution, how to fix it

Sections with empty lines are not parsing

Sections are not parsing, if:

  • Section data is after an empty line. Example:
Options:

    -h, --help                                                  output usage information
    -V, --version                                               output the version number

Examples:

    htmlhint

Please, fix it.

Make prefixes configurable

Now, users are not able to configure prefixes of arguments (linterhub:, args:). Please, make it configurable.

Add new property to configuration

Please, add new property "parseWhole" [boolean] to configuration.

If it true and no sections with names and postfixes was found, the whole file will be parsed. Each part, which starts at new line and begin with "-" will be parsed as option, and part between option and next option will be parsed as option description.

Description not fully parsed when have more than one space

If description of option have two spaces between words or parts, will be parsed only first part before two spaces. Please, fix it.

Also, when description multiline, each line concatenates with previous without spaces.

Also, when description multiline, argument name becomes "null".

Add packages tests with gulp

Please, add packages tests (one valid and one failing) with gulp. Tests should be:

  • get helps of packages from given array of package names (with help of npx)
  • send this helps to parser() and parse it
  • with the help of gulp, identify, if parsing is clear or it is failing and print errors

Add init docs

Please, add inital docs:

  • package.json
  • gitignore
  • README.md - with structure
  • e.t.c

Add tests of sections

Please, add tests of sections (with help of chai) what are using in parser.

Tests:

  • if section is absent (for every section)
  • if section consist invalid data (for every section)
  • if there are other sections, what are not in use in parser

Move configuration to a separate file

Now, all configuration of parsing is in handle.js file. It is better to move configuration to a separate file.

We have next config:

  • object argumentTemplate, that is a template for an array of objects, that return by handle()
  • object context, that has configuration of sections and its data.

Create base functionality of parser

Please, create base implementation of parser function:

  • add function to parse linter's help (w/o implementation)
  • add function to templatise result schema (w/o implementation, only template import)

Create implementation for handle function

Please, create implementation for handle function. This function should:

  1. Get all suitable sections from parseSection function
  2. Send it to splitSection function, which will split sections into options
  3. Get a two-dimensional array of all options from parseOption function

Create implementation for parseOption function

Please, create implementation for parseOption function, which should slice an option with description into array and return it. This array will be write into json later.

Structure of array:

  • option (short version)
  • option (long version)
  • boolean, if option has value (needed later to add prefix "args:" if true)
  • default value of option
  • description of option

Convert Usage output to JSON

Convert the information about the commands, options and flags of console app to JSON Object. This information is usually available when executing help command (possible synonyms: -h, --help, ?, etc.).

Example from docopt project:

Naval Fate.

Usage:
  naval_fate ship new <name>...
  naval_fate ship <name> move <x> <y> [--speed=<kn>]
  naval_fate ship shoot <x> <y>
  naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate -h | --help
  naval_fate --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

So, this information could be parsed and converted to JSON similar to args definition. It should describe available arguments/commands/flags, name, type (if possible), default value and so on. There is no need to create exactly the same structure, args mentioned just as an example.

Implementation should include:

  • The JSON schema of result (if it will be not the same as args above);
  • Console app that able to parse a string with usage information and return JSON object according to schema;
  • In case of any errors or if parsing failed by any reason - output a message with detailed explanation;
  • Pre-processing logic that may clean up and restructure input string to make it parsable;

Some examples for args schema are here.

When constructing JSON Object give attention to next recommendation:

  • Use full names of arguments. E.g. --help, not -h

Add features to index.js

User should be able to send config and help (which will be parsed) as:

  1. path to file
  2. stdin

Please, add this features to index.js.

Add linting to project

Please, add a linting to project.

Next comands:

  • lint - command to check all json and js files on project
  • before-commit - runs before each of commit. Include: lint

Recommendation:

  • eslint - for linting
  • husky - for run before-commit command

Add tests of result of parsed help

Please, add tests of result of parser. Tests have input string & output json and should compare result of parsing input string with output json, what should be.

Fixes in parsing

I've found next errors:

  • when description is fully on next line with option, it is not parsing
  • exception when postfix or names [config] is string (not an array)
  • parseWhole always changing to default config value

Change algorithm of section parsing

Now, it is parsing only one section name. But, some linters have "Options" instead of "Options:", or custom names: "Basic configuration:" (example from eslint).

Please, change algorithm of parsing of required sections (now it is only section "Options:") to the same way:

  • Trying to parse primary names "Options:" and "Options:\n", if it not found, next:
  • Trying to parse secondary names "Options" (other patterns may be added later), if it not found, next:

Different sections not parse

Please, fix 2 problems:

  • different sections not parsing, only first
  • section name isn't passed to the findSection function

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.