Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Gengetopt-like lib for parsing command line args for Node
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
release
.gitignore
README.md
build.js
grammar.peg
tests.js

README.md

Gengetopt-Js

Gengetopt-like lib for parsing command line args for Node

A simple lib for parsing pairs of named command line arguments (behaviour is undefined for non-named arguments, sorry ...), for node.

Check the dir release/ for the actual module's code. Anything outside that folder is not included in the module.

To Build

You'll need the pegjs module.

Instalation:

npm install gengetopt-js

Usage:

Use the parseArgs function to parse the process's argv object. Use the transf property of the result, which contains all your args in a dictionary. The raw and parsed properties are just for bookkeping...

var r = require('gengetopt-js')

process.argv ['node', 'dummy.js', '-d', 'some string', '-s', 123]

var args = r.parseArgs(process.argv)

JSON.stringify(args) '{"raw":["node","dummy.js","-d","some string","-s",123],"parsed":[["d","some string"],["s","123"]],"transf":{"d":"some string","s":"123"}}'

JSON.stringify(args.transf) '{"d":"some string","s":"123"}'

JSON.stringify(args.parsed) '[["d","some string"],["s","123"]]'

JSON.stringify(args.raw) '["node","dummy.js","-d","some string","-s",123]'

Something went wrong with that request. Please try again.