argvsus
v1.0.0
Published
Flags, arguments, actions, and documentation for `process.argv` in Node.js or io.js
Downloads
1
Readme
Process v1.0.0
Process
helps your terminal scripts support flags, arguments, actions, and documentation!
The exported types are Process
, Process.Action
, and Process.Flag
.
var Process = require("Process")
To run the tests:
$ npm install
$ grunt test
To export to js/index.js
:
$ grunt export
Example
This is the terminal input:
$ node path/to/npm/bin.js install --global --nodedir path/to/node --force Process
This is what path/to/npm/bin.js
looks like:
// Used in the case of a --help flag.
process.help = ["The package manager for Node."]
// Add flags for the primary command (eg: 'npm --version')
process.flags = {
version: {
short: "v",
args: 0,
help: "Echoes the current version of NPM."
}
}
// Add subcommands for the primary command (eg: 'npm install')
process.actions = {
install: {
short: "i",
help: "Install the dependencies in the local node_modules folder."
}
}
// Flags for the 'install' subcommand (eg: 'npm install -g')
process.actions.install.flags = {
global: {
short: "g",
args: 0,
help: "Installs the given dependencies into the global node_modules folder."
}
}
require("Process")(process).parse()
These are the new properties available after parse()
is called:
process.script = [
"node",
"path/to/npm/bin.js"
]
process.actions = [
"npm",
"install"
]
process.flags = {
global: true,
nodedir: "path/to/node",
force: true
}
process.args = [
"Process"
]
Process.prototype
parse()
Arguments: (ArrayOf(String)
or Undefined
)
Once you wrap your process
object with Process()
, call process.parse()
and you'll have full access to the properties listed here.
Normally, you won't pass an array of strings to this. Instead, the process.argv
array will be used.
Before you call this, make sure you have process.flags
, process.actions
, process.action
, and process.help
all set to your liking.
help
Type: String
or ArrayOf(String)
A description of your script.
This is shown when the --help
flag is passed.
If an array of strings is passed, it is joined with "\n"
.
flags
Type: Object
Before process.parse()
:
The valid flag names and their option objects.
After process.parse()
:
The passed flag names and their arguments.
Learn more about Process.Flag.
actions
Type: Object
Before process.parse()
:
The valid action names and their option objects.
After process.parse()
:
No value.
Learn more about Process.Action.
options
Type: Object
Contains the values of process.flags
and process.actions
before process.parse()
was called.
command
Type: ArrayOf(String)
script
Type: ArrayOf(String)
The command used to run this script. (eg: node path/to/my-module/index.js
)
Process.Action
Note: You'll never have to construct one of these on your own. Instead, use process.options.addAction
or define process.actions
before process.parse()
.
name
Note: This is implemented, but not yet documented.
help
Note: This is implemented, but not yet documented.
example
Note: This is implemented, but not yet documented.
action
Note: This is implemented, but not yet documented.
actions
Note: This is implemented, but not yet documented.
flags
Note: This is implemented, but not yet documented.
default
Note: This is implemented, but not yet documented.
validate
Note: This is not yet implemented.
transform
Note: This is not yet implemented.
Process.Flag
Note: You'll never have to construct one of these on your own. Instead, use process.options.addFlag
or define process.flags
before process.parse()
.
name
The many-letter ID of this Flag
.
short
A string to map a single-letter flag (eg: -f
) to a many-letter flag (eg: --force
).
help
An array of strings to describe what this Flag
is used for.
example
An array of strings to describe how to use this Flag
.
default
A function that returns a default value.
Only called when this Flag
has no arguments.
Can be undefined
.
validate
A function that verifies whether this Flag
's arguments are valid by returning true
or false
.
Can be undefined
.
Note: Called before the default value is applied to the Flag
.
transform
A function that mutates this Flag
's arguments and returns a new value.
Can be undefined
.
Note: Called after the default value is applied to this Flag
.
args
The maximum number of arguments possibly associated with this Flag
.