0.0.3 • Published 6 years ago

trujs-cmdargs v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

TruJS.cmdArgs

A simple module for parsing command line arguments in NodeJS.

This module returns a simple worker function that takes an argv array and returns a CmdArgs object, representing the arguments.

Usage
var cmdArgs = require("trujs-cmdargs")(process.argv);
Command Line Parts
node cli.js listen --config secure,port:3000 -fvt --serve -g
nodescriptcommandnamed-optionflag arraynamed-optionflag
nodecli.jslisten--config secure,port:3000-fvt--serve-g
  • command: The first argument after the script path, before any named-options or flags.
  • named-option: Any argument that is prefixed with a double dash ("--"); can be followed by an array of value and/or name:value members.
  • flag array: Any argument that is prefixed with a single dash ("-"); each character is an individual flag.
Example
node cli.js listen --config secure,port:3000 -fvt --serve
  • listen: The Command
  • --config: A named-option with the value secure,port:3000
  • -fvt: Flags f, v, and t
  • --serve: A named-option without a value
{
    "_executable": "node"
    , "_script": "cli.js"
    , "command": "listen"
    , "oridnals": ["config","serve"]
    , "flags": ["f","v","t"]
    , "config": [
        "secure"
        , {
            "name": "port"
            , "value": "3000"
        }
    ]
    , "serve": null
}
Static Members
MemberDescription
_executableAlways node (argv[0]).
_scriptThe path to the JavaScript file, i.e. the argument following node in the command line (argv[1]).
commandThe first option following the path as long as it'snot a named-option or flag (Default null).
flagsAn array of flags, in the order they appeared in (Defaultempty array)
ordinalsAn array of named-option names, in the order they appearedin the command line arguments.