All Projects → lukeed → Mri

lukeed / Mri

Licence: mit
Quickly scan for CLI flags and arguments

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mri

Fast Xml Parser
Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
Stars: ✭ 1,021 (+159.14%)
Mutual labels:  cli, command-line, parser
Kong
Kong is a command-line parser for Go
Stars: ✭ 481 (+22.08%)
Mutual labels:  command-line, parser, flags
Entrypoint
Composable CLI Argument Parser for all modern .Net platforms.
Stars: ✭ 136 (-65.48%)
Mutual labels:  cli, command-line, parser
Args
Toolkit for building command line interfaces
Stars: ✭ 399 (+1.27%)
Mutual labels:  cli, command-line, flags
Spectre.cli
An extremely opinionated command-line parser.
Stars: ✭ 121 (-69.29%)
Mutual labels:  cli, command-line, parser
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (-68.02%)
Mutual labels:  cli, command-line, parser
Picocli
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
Stars: ✭ 3,286 (+734.01%)
Mutual labels:  cli, command-line, parser
Caporal.js
A full-featured framework for building command line applications (cli) with node.js
Stars: ✭ 3,279 (+732.23%)
Mutual labels:  cli, command-line
Swagger Cli
Swagger 2.0 and OpenAPI 3.0 command-line tool
Stars: ✭ 321 (-18.53%)
Mutual labels:  cli, parser
Pipupgrade
🗽 Like yarn outdated/upgrade, but for pip. Upgrade all your pip packages and automate your Python Dependency Management.
Stars: ✭ 391 (-0.76%)
Mutual labels:  cli, command-line
Cmd2
cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python
Stars: ✭ 342 (-13.2%)
Mutual labels:  cli, command-line
Swaggen
OpenAPI/Swagger 3.0 Parser and Swift code generator
Stars: ✭ 385 (-2.28%)
Mutual labels:  cli, parser
Php Console
🖥 PHP CLI application library, provide console argument parse, console controller/command run, color style, user interactive, format information show and more. 功能全面的PHP命令行应用库。提供控制台参数解析, 命令运行,颜色风格输出, 用户信息交互, 特殊格式信息显示
Stars: ✭ 310 (-21.32%)
Mutual labels:  cli, command-line
Fd
A simple, fast and user-friendly alternative to 'find'
Stars: ✭ 19,851 (+4938.32%)
Mutual labels:  cli, command-line
Whatspup
🔳 WhatsApp chat from commandline/console/cli using GoogleChrome puppeteer
Stars: ✭ 310 (-21.32%)
Mutual labels:  cli, command-line
Xidel
Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
Stars: ✭ 335 (-14.97%)
Mutual labels:  cli, command-line
Pastel
A command-line tool to generate, analyze, convert and manipulate colors
Stars: ✭ 3,742 (+849.75%)
Mutual labels:  cli, command-line
Go Tea
Tea provides an Elm inspired functional framework for interactive command-line programs.
Stars: ✭ 329 (-16.5%)
Mutual labels:  cli, command-line
Beats
A command-line drum machine. Convert a beat notated in YAML into a *.wav file.
Stars: ✭ 389 (-1.27%)
Mutual labels:  cli, command-line
Sad
CLI search and replace | Space Age seD
Stars: ✭ 350 (-11.17%)
Mutual labels:  cli, command-line

mri Build Status

Quickly scan for CLI flags and arguments

This is a fast and lightweight alternative to minimist and yargs-parser.

It only exists because I find that I usually don't need most of what minimist and yargs-parser have to offer. However, mri is similar enough that it might function as a "drop-in replacement" for you, too!

See Comparisons for more info.

Install

$ npm install --save mri

Usage

$ demo-cli --foo --bar=baz -mtv -- hello world
const mri = require('mri');

const argv = process.argv.slice(2);

mri(argv);
//=> { _: ['hello', 'world'], foo:true, bar:'baz', m:true, t:true, v:true }

mri(argv, { boolean:['bar'] });
//=> { _: ['baz', 'hello', 'world'], foo:true, bar:true, m:true, t:true, v:true }

mri(argv, {
  alias: {
    b: 'bar',
    foo: ['f', 'fuz']
  }
});
//=> { _: ['hello', 'world'], foo:true, f:true, fuz:true, b:'baz', bar:'baz', m:true, t:true, v:true }

API

mri(args, options)

Return: Object

args

Type: Array
Default: []

An array of arguments to parse. For CLI usage, send process.argv.slice(2). See process.argv for info.

options.alias

Type: Object
Default: {}

An object of keys whose values are Strings or Array<String> of aliases. These will be added to the parsed output with matching values.

options.boolean

Type: Array|String
Default: []

A single key (or array of keys) that should be parsed as Booleans.

options.default

Type: Object
Default: {}

An key:value object of defaults. If a default is provided for a key, its type (typeof) will be used to cast parsed arguments.

mri(['--foo', 'bar']);
//=> { _:[], foo:'bar' }

mri(['--foo', 'bar'], {
  default: { foo:true, baz:'hello', bat:42 }
});
//=> { _:['bar'], foo:true, baz:'hello', bat:42 }

Note: Because --foo has a default of true, its output is cast to a Boolean. This means that foo=true, making 'bar' an extra argument (_ key).

options.string

Type: Array|String
Default: []

A single key (or array of keys) that should be parsed as Strings.

options.unknown

Type: Function
Default: undefined

Callback that is run when a parsed flag has not been defined as a known key or alias. Its only parameter is the unknown flag itself; eg --foobar or -f.

Once an unknown flag is encountered, parsing will terminate, regardless of your return value.

Note: mri only checks for unknown flags if options.unknown and options.alias are populated. Otherwise, everything will be accepted.

Comparisons

minimist

  • mri is 5x faster (see benchmarks)
  • Numerical values are cast as Numbers when possible
    • A key (and its aliases) will always honor opts.boolean or opts.string
  • Short flag groups are treated as Booleans by default:
    minimist(['-abc', 'hello']);
    //=> { _:[], a:'', b:'', c:'hello' }
    
    mri(['-abc', 'hello']);
    //=> { _:[], a:true, b:true, c:'hello' }
    
  • The opts.unknown behaves differently:
    • Unlike minimist, mri will not continue continue parsing after encountering an unknown flag
  • Missing options:
    • opts.stopEarly
    • opts['--']
  • Ignores newlines (\n) within args (see test)
  • Ignores slashBreaks within args (see test)
  • Ignores dot-nested flags (see test)

yargs-parser

  • mri is 40x faster (see benchmarks)
  • Numerical values are cast as Numbers when possible
    • A key (and its aliases) will always honor opts.boolean or opts.string
  • Missing options:
    • opts.array
    • opts.config
    • opts.coerce
    • opts.count
    • opts.envPrefix
    • opts.narg
    • opts.normalize
    • opts.configuration
    • opts.number
    • opts['--']
  • Missing parser.detailed() method
  • No additional configuration object
  • Added options.unknown feature

Benchmarks

Running Node.js v10.13.0

minimist      x    312,417 ops/sec ±0.85% (93 runs sampled)
mri           x  1,641,208 ops/sec ±0.24% (93 runs sampled)
nopt          x    910,276 ops/sec ±1.11% (88 runs sampled)
yargs-parser  x     40,943 ops/sec ±1.37% (93 runs sampled)

License

MIT © Luke Edwards

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].