1.1.2 • Published 2 years ago

manchego v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

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

  • Arguments preceeding single- or double- hyphen options are set to true
  • Single- and double- hyphen options can receive space separated values
  • Multiple arguments can be passed to the last single- or double- hyphen option
  • Single-hyphen options can be combined
  • Double-hyphen options are stored in camelCase
  • 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
1.1.2

2 years ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.9.5

5 years ago

0.9.4

5 years ago

0.9.3

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago