1.0.8 • Published 3 years ago

kawkah-parser v1.0.8

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

The argument parser for Kawkah. If you're looking for a full blow CLI parser you probably want Kawkah. You can think of kawkah-parser as sort of a normalizer before you would validate the parsed result against a schema then trigger perhaps an action. If you simply want to parse whatcha got and then handle constraints/coercion yourself kawkah-parser works great.

Install

$ npm install kawkah-parser

Usage

import { parse } from 'kawkah-parser';
const args = 'install /some/path names... tim sally joe --user.name bob --force --tags red --tags blue -abc -vvvvv --no-rename';
const result = parse();

Your result would be:

result = {
  _: ['install', '/some/path'],
  force: true,
  tags: ['red', 'blue'],
  names: ['jim', 'sally', 'joe'],
  user: { name: 'bob' },
  a: true,
  b: true,
  c: true,
  v: 5,
  rename: false,
  __: []
};

Options

For addtional option detail and API info see Docs below.

charVariadic

Character denoting variadic arguments.

const args = 'create blog java... c python javascript'
const result = parse(args);

Result would be:

result = {
  _: ['create', 'blog', ['java', 'c', 'python', 'javascript']],
};

charAbort

Character used to abort parsing of args.

const args = 'create blog -- ignore1 ignore2'
const result = parse(args);

Result would be:

result = {
  _: ['create', 'blog'],
  __: ['ignore1', 'ignore2']
};

charNegate

Character used to negate boolean flags.

const args = '--no-force'
const result = parse(args);

Result would be:

result = {
  force: false
};

allowParseBooleans

Allows parsing flags as boolean.

allowParseNumbers

Allows parsing number like values.

allowCamelcase

Allow converting some-flag to someFlag.

allowShortExpand

Allows expanding -abc to -a -b -c.

allowShortValues

Allows short flags to have values.

allowDuplicateOptions

Allows --tag red --tag green --tag blue which will be stored in an array.

allowDotNotation

Allows --user.name bob to result in { name: 'bob'}.

allowBoolNegation

Allows --no-force to set --force flag to false.

allowCountOptions

Allows -vvvvv to result in { v: 5 }.

allowVariadics

Allows arguments to be grouped in an array.

allowAnonymous

Allows anonymous arguments when false flags/args must have configuration.

allowExtendArgs

When true args in _ are extend to result object by name.

allowPlaceholderArgs

When true result._ args set as null when no value.

allowPlaceholderOptions

When true if a configured option is not present a placeholder is set.

onParserError

When null errors are thrown otherwise handled by specified handler.

Docs

See https://blujedis.github.io/kawkah-parser/

Change

See CHANGE.md

License

See LICENSE.md