1.8.4 • Published 3 years ago

nezparser v1.8.4

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Nezparser

Nezparser is a simple light parser for building cli with node.js.

Installation

using npm npm i nezparser

using yarn yarn add nezparser

Setup

use nezparser.setup() to configure your cli.

apitypedescriptionrequired
usageStringExplain how to use your cli.Yes
optionsoptionsDefine options the user can use.No
commandscommandsDefine the commands the user can use.No
nezparser.setup({
  usage: 'commity <command> <options>',
  options: [
    {
      name: '--push',
      alias: '-p',
      description: 'push changes to current remote branch after commiting',
    },
    {
      name: '--addAll',
      alias: '-a',
      description: 'add all staged changes before commiting',
    },
  ],
  commands: [
    {
      name: 'init',
      description: 'inititialize Commity',
      options: [
        {
          name: '--overwrite',
          alias: '-o',
          description: 'overwrite existing config (if exist)',
        },
      ],
    },
  ],
});

Parse

Once you have setup nezparser, you have to use nezparser.parse() before accessing commands and options.

Commands

:pushpin: You have to use nezparser.parse() Parse before nezparser.hasCommand(command: string)

|Api|Return type|Description| |-||| |Function commandUsed(command: string)|Boolean|Allow you to know if a command is used.

const nezparser = require('nezparser');

nezparser.setup({
  // ...
});
nezparser.parse();
if (nezparser.commandUsed('init')) {
  console.log('Command "init" used');
};

Help

Nezparser includes help command that output cli usage, commands and options.

Options

:pushpin: You have to use nezparser.parse() Parse before nezparser.hasOption(option: string, alias: string)

ApiReturn typeDescription
Function hasOption(option: string, alias: string)BooleanAllow you to know if an option is used.
const nezparser = require('nezparser');

nezparser.setup({
  // ...
});
nezparser.parse();
if (nezparser.hasOption('--foo', '-f',)) {
  console.log('--foo option passed');
}
1.8.4

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.8.3

3 years ago

1.7.5

3 years ago

1.7.4

3 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago