manchego
Cheesy CLI
Last updated 7 months ago by luketeaford .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install manchego 
SYNC missed versions from official npm registry.

Manchego

Build Status Coverage Status

Design Goals

Manchego is a tool for making Command Line Interfaces. It uses simple rules instead of making up a syntax with special characters. It has no defaults or side effects. It always returns an object.

What it Does

  • [x] Arguments preceeding single- or double- hyphen options are set to true
  • [x] Single- and double- hyphen options can receive space separated values
  • [x] Multiple arguments can be passed to the last single- or double- hyphen option
  • [x] Single-hyphen options can be combined
  • [x] Double-hyphen options are stored in camelCase
  • [x] Double-hyphen options can receive an argument with an equals sign

Usage Examples

Overview of All Rules

# If this is your input...
node index.js say -a ape -bd --cool-urls --o ox --file=foo.js -z zappa zip zoo
// ...index.js will work like this
const manchego = require('manchego')

// Pass process.argv into the manchego function which returns an object
const cli = manchego(process.argv)

// Arguments preceding single- or double- hyphen options are set to true
cli.say // true

// Single- and double- hyphen options can receive space separated values
cli.a // 'ape'
cli.o // 'ox'

// Multiple arguments can be passed to the last single- or double- hyphen option
cli.z // 'zappa zip zoo'

// Single-hyphen options can be combined
cli.b // true
cli.d // true

// Double-hyphen options are stored in camelCase
cli.coolUrls // true

// Double-hyphen options can receive an argument with an equals sign
cli.file // 'foo.js'

Converting 'True' and 'False' to Booleans

In v1.1.0, Manchego adds a convertBooleans option:

# If this is your input...
node index.js whatever --show-warnings false --have-fun true
// ... You can use convertBooleans from manchego
const manchego = require('manchego').convertBooleans

// Destructure the object for ease of use
const { showWarnings, haveFun } = manchego(process.argv)
showWarnings // false
haveFun // true

Miscellaneous Tips

# If this is your input...
node index.js whatever -w squarewave --source src/md --show-warnings false -rmx
// ...index.js will work like this
const manchego = require('manchego')

// Destructure the object manchego returns for ease of use
const { whatever, w, source, showWarnings, r, m, x } = manchego(process.argv)
whatever && r && m && x // true
w // 'squarewave'
source // 'src/md'

// Sometimes it's useful to set an option true by default
// Remember manchego does not convert any value ('false' string instead of boolean)...
showWarnings // 'false'

// ...but it's trivial to do that in your code like so
const showWarningsEnabled = showWarnings !== 'false' // false

Current Tags

  • 1.1.0                                ...           latest (7 months ago)

20 Versions

  • 1.1.0                                ...           7 months ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.9.5                                ...           a year ago
  • 0.9.4                                ...           a year ago
  • 0.9.3                                ...           a year ago
  • 0.9.2                                ...           a year ago
  • 0.9.1                                ...           a year ago
  • 0.9.0                                ...           a year ago
  • 0.8.0                                ...           a year ago
  • 0.7.2                                ...           a year ago
  • 0.7.1                                ...           a year ago
  • 0.7.0                                ...           a year ago
  • 0.6.0                                ...           a year ago
  • 0.5.0                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |