Skip to content

dynamically construct a command line parser based on the object provided to it

Notifications You must be signed in to change notification settings

matutter/arg-to-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status dependencies Status

ARG-TO-OBJECT

ATO is a quick-and-dirty argument parser meant for situations when a complicated CLI isn't necessary.

Use process.argv by default.

const ato = require('arg-to-object')
var params = ato.parse()

An object can be used for defaults.

// node sample.js -files a b c -r false
var defaults = { files: [], recursive: true }
var params = ato.parse(defaults)

/*
 * {
 *   files: ["a", "b", "c"],
 *   recursive: false
 * }
 */

Argument shorthands are expanded by a simple prefix-search

// node sample.js -f a b c -r 
params = ato.parse(defaults)

/* '-f' extends to 'files'
 * { files: ["a", "b", "c"], ... }
 */ 

Pass in arguments manually.

ato.parse(process.argv, defaults)

Without a default object, the parsed object is constructed with -taks as keys. The arguments -f a b c -r will yield

{
  f: ["a", "b", "c"],
  r: true
}

Type interpolation examples.
args=-r result={r: true}
args=-r 1 2 3 result={r: [1, 2, 3]}
args=-r false result={r: false}
args=-r -f hello result={r: true, f: 'hello'}

About

dynamically construct a command line parser based on the object provided to it

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published