simple-argparse
Advanced tools
Comparing version 0.3.0 to 1.0.0
87
index.js
/* | ||
| simple-argparse | ||
| simple argument parser for command line applications | ||
| | ||
| Author: GochoMugo <mugo@forfuture.co.ke> | ||
| Copyright (c) Forfuture LLC <we@forfuture.co.ke> | ||
| License: MIT | ||
*/ | ||
| simple-argparse | ||
| simple argument parser for command line applications | ||
| | ||
| Author: GochoMugo <mugo@forfuture.co.ke> | ||
| Copyright (c) Forfuture LLC <we@forfuture.co.ke> | ||
| License: MIT | ||
*/ | ||
@@ -15,9 +15,9 @@ | ||
// npm-installed modules | ||
var argv = require("minimist"); | ||
var argv = require("yargs-parser"); | ||
/** | ||
* Shifts the process arguments removing the node executable and | ||
* filepath. leaving the rest or arguments | ||
* This function is _impure_. It relies on _process.argv_ | ||
* Slices the process arguments removing the node executable and | ||
* filepath, leaving the rest of the arguments. | ||
* This function is _impure_; it relies on _process.argv_ | ||
* | ||
@@ -27,6 +27,3 @@ * @return {Array} arguments | ||
function processArgv() { | ||
var args = process.argv.slice(); | ||
args.shift(); // node | ||
args.shift(); // filename/command-name | ||
return args; | ||
return process.argv.slice(2); | ||
} | ||
@@ -36,4 +33,3 @@ | ||
/** | ||
* Wraps padding space around some text, specfically by adding spaces | ||
* at the end of text | ||
* Appends padding space to some text. | ||
* | ||
@@ -62,3 +58,3 @@ * @param {String} text | ||
/** | ||
* Returns `true` if `variable` is a String. Otherwise `false` | ||
* Returns `true` if `variable` is a String. Otherwise `false`. | ||
* | ||
@@ -74,3 +70,15 @@ * @param {*} variable | ||
/** | ||
* Parser | ||
* Returns `true` if `variable` is an Array. Otherwise `false`. | ||
* | ||
* @param {*} variable | ||
* @return {Boolean} | ||
*/ | ||
function isArray(variable) { | ||
return variable instanceof Array; | ||
} | ||
/** | ||
* Parser. | ||
* | ||
* @constructor | ||
@@ -98,3 +106,4 @@ * @param {Function} stdout - passed output | ||
/** | ||
* Adds Name and/or Description to the Parser | ||
* Adds Name and/or Description to the Parser. | ||
* | ||
* @param {String} [name] | ||
@@ -116,3 +125,4 @@ * @param {String} text | ||
/** | ||
* Adds Version information | ||
* Adds Version information. | ||
* | ||
* @param {String} versionNum | ||
@@ -128,3 +138,4 @@ * @return {Parser} this Parser instance | ||
/** | ||
* Adds an option/command | ||
* Adds an option/command. | ||
* | ||
* @param {String} [alias] | ||
@@ -171,3 +182,4 @@ * @param {String} command | ||
/** | ||
* Adds the default function to run if no command is specified | ||
* Adds the default function to run if no command is specified. | ||
* | ||
* @param {Function} func | ||
@@ -185,3 +197,3 @@ * @return {Parser} this Parser instance | ||
/** | ||
* Add a pre-run function | ||
* Add a pre-run function. | ||
* | ||
@@ -200,3 +212,4 @@ * @param {Function} func | ||
/** | ||
* Adds a bottom epilog | ||
* Adds a bottom epilog. | ||
* | ||
* @param {String} epilog | ||
@@ -212,4 +225,5 @@ * @return {Parser} this Parser instance | ||
/** | ||
* Parses a string for commands | ||
* @param {String} commandString | ||
* Parses a string for commands. | ||
* | ||
* @param {String|Array} cmds - commands/args | ||
* @return {Parser} this Parser instance | ||
@@ -219,3 +233,10 @@ */ | ||
var me = this; | ||
var args = isString(cmds) ? cmds.split(" ") : processArgv(); | ||
var args; | ||
if (isString(cmds)) { | ||
args = cmds.split(" "); | ||
} else if (isArray(cmds)) { | ||
args = cmds; | ||
} else { | ||
args = processArgv(); | ||
} | ||
var context = { }; | ||
@@ -249,4 +270,5 @@ var command = args[0]; | ||
/** | ||
* Show help: name, description, options and epilog strings are | ||
* passed to the output function | ||
* Show help information; name, description, options and epilog strings are | ||
* passed to the output function. | ||
* | ||
* @return {Parser} this Parser instance | ||
@@ -277,4 +299,5 @@ */ | ||
/** | ||
* Show version: name and version strings are passed to the output | ||
* function | ||
* Show version information; name and version strings are passed to the | ||
* output function. | ||
* | ||
* @return {Parser} this Parser instance | ||
@@ -281,0 +304,0 @@ */ |
{ | ||
"name": "simple-argparse", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"description": "Simple Argument parser for Command-line Applications", | ||
@@ -24,14 +24,15 @@ "homepage": "https://github.com/forfutureLLC/node-simple-argparse", | ||
"dependencies": { | ||
"minimist": "^1.1.2" | ||
"yargs-parser": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^2.11.3", | ||
"grunt": "^0.4.5", | ||
"grunt-cli": "^0.1.13", | ||
"grunt-eslint": "^17.0.0", | ||
"grunt": "^1.0.1", | ||
"grunt-cli": "^1.2.0", | ||
"grunt-eslint": "^18.1.0", | ||
"grunt-mocha-test": "^0.12.7", | ||
"istanbul": "^0.3.17", | ||
"istanbul": "^0.4.3", | ||
"load-grunt-tasks": "^3.2.0", | ||
"mocha-lcov-reporter": "^0.0.2", | ||
"should": "^7.0.2" | ||
"mocha": "^2.5.3", | ||
"mocha-lcov-reporter": "^1.2.0", | ||
"should": "^9.0.0" | ||
}, | ||
@@ -38,0 +39,0 @@ "scripts": { |
@@ -6,3 +6,7 @@ | ||
[![node](https://img.shields.io/node/v/simple-argparse.svg?style=flat-square)](https://www.npmjs.com/package/simple-argparse) [![npm](https://img.shields.io/npm/v/simple-argparse.svg?style=flat-square)](https://www.npmjs.com/package/simple-argparse) [![Travis](https://img.shields.io/travis/forfutureLLC/node-simple-argparse.svg?style=flat-square)](https://travis-ci.org/forfutureLLC/node-simple-argparse) [![Gemnasium](https://img.shields.io/gemnasium/forfutureLLC/node-simple-argparse.svg?style=flat-square)](https://gemnasium.com/forfutureLLC/node-simple-argparse) [![Coveralls](https://img.shields.io/coveralls/forfutureLLC/node-simple-argparse.svg?style=flat-square)](https://coveralls.io/github/forfutureLLC/node-simple-argparse?branch=master) | ||
[![node](https://img.shields.io/node/v/simple-argparse.svg?style=flat-square)](https://www.npmjs.com/package/simple-argparse) | ||
[![npm](https://img.shields.io/npm/v/simple-argparse.svg?style=flat-square)](https://www.npmjs.com/package/simple-argparse) | ||
[![Travis](https://img.shields.io/travis/forfuturellc/node-simple-argparse.svg?style=flat-square)](https://travis-ci.org/forfuturellc/node-simple-argparse) | ||
[![Gemnasium](https://img.shields.io/gemnasium/forfuturellc/node-simple-argparse.svg?style=flat-square)](https://gemnasium.com/forfuturellc/node-simple-argparse) | ||
[![Coveralls](https://img.shields.io/coveralls/forfuturellc/node-simple-argparse.svg?style=flat-square)](https://coveralls.io/github/forfuturellc/node-simple-argparse?branch=master) | ||
@@ -98,6 +102,6 @@ | ||
* __Parser#parse([arguments:String])__ | ||
* __Parser#parse([arguments:String|Array])__ | ||
* __arguments__:(Optional) | ||
* a string representing commands as typed in command-line | ||
* a string or array representing options, for example, `"name --key=value"`, `["name", "--key=value"]` | ||
* if left out, `process.argv` will be used instead | ||
@@ -119,3 +123,3 @@ | ||
All arguments parsed by `.parse()` are processed using | ||
[minimist][minimist], and made available to the __option functions__ as | ||
[yargs-parser][argv], and made available to the __option functions__ as | ||
their `this` argument. | ||
@@ -183,3 +187,3 @@ | ||
See [minimist][minimist] for more information on the parsing. | ||
See [yargs-parser][argv] for more information on the parsing. | ||
@@ -194,5 +198,5 @@ The __option function__ is optional. If it is left out, the option will | ||
Copyright (c) 2014-2015 Forfuture LLC <we@forfuture.co.ke> | ||
Copyright (c) 2014-2016 Forfuture LLC <we@forfuture.co.ke> | ||
[minimist]:https://github.com/substack/minimist | ||
[argv]:https://github.com/yargs/yargs-parser |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
16181
6
270
0
198
10
+ Addedyargs-parser@^2.4.0
+ Addedcamelcase@3.0.0(transitive)
+ Addedlodash.assign@4.2.0(transitive)
+ Addedyargs-parser@2.4.1(transitive)
- Removedminimist@^1.1.2
- Removedminimist@1.2.8(transitive)