From 7cea94440490879a03ef5dc16a9195814c04e399 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 6 Jun 2016 14:03:11 +0300 Subject: [PATCH 1/9] Replace dep 'minimist' with 'yargs-parser' --- CHANGELOG.md | 13 +++++++++++++ README.md | 6 +++--- index.js | 2 +- package.json | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..940ee6b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ + +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + + +## Unreleased + +Changed: + +* Replace dependency [minimist](https://github.com/substack/minimist) with + [yargs-parser](https://github.com/yargs/yargs-parser) diff --git a/README.md b/README.md index cbf336a..e56aaa5 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ A `Parser` has these methods: ## Parsing 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. An __option function__ refers to the function passed to `.option`. @@ -177,7 +177,7 @@ suite === someSuite ``` -See [minimist][minimist] for more information on the parsing. +See [yargs-parser][argv] for more information on the parsing. The __option function__ is optional. If it is left out, the option will be ignored. This may be useful for commands __not yet implemented__. @@ -190,4 +190,4 @@ __The MIT License (MIT)__ Copyright (c) 2014-2015 Forfuture LLC -[minimist]:https://github.com/substack/minimist +[argv]:https://github.com/yargs/yargs-parser diff --git a/index.js b/index.js index ead4d2a..dbd1231 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ // npm-installed modules -var argv = require("minimist"); +var argv = require("yargs-parser"); /** diff --git a/package.json b/package.json index 1512e6f..90d9a2e 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "author": "GochoMugo ", "main": "index.js", "dependencies": { - "minimist": "^1.1.2" + "yargs-parser": "^2.4.0" }, "devDependencies": { "coveralls": "^2.11.3", From d531f585e88b8c901d82df68a7b0b7ddcae11ad0 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 6 Jun 2016 14:06:42 +0300 Subject: [PATCH 2/9] Fix broken links for badges --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e56aaa5..95b466b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,11 @@ > Simple Argument parser for Command-line Applications -[![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) ## installation From 11f57f710393bae78308fe747e5cbf4700f8bb42 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 6 Jun 2016 14:21:21 +0300 Subject: [PATCH 3/9] Update license --- LICENSE | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index ebf62b1..eb4a711 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2015 Forfuture LLC +Copyright (c) 2014-2016 Forfuture LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated diff --git a/README.md b/README.md index 95b466b..cf95a6c 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ be ignored. This may be useful for commands __not yet implemented__. __The MIT License (MIT)__ -Copyright (c) 2014-2015 Forfuture LLC +Copyright (c) 2014-2016 Forfuture LLC [argv]:https://github.com/yargs/yargs-parser From 39a9d01b4cfc2ef343d404a092c161b46b007221 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 6 Jun 2016 14:39:48 +0300 Subject: [PATCH 4/9] Allow passing an `Array` of args to `Parser#parse()` --- CHANGELOG.md | 4 ++++ README.md | 4 ++-- index.js | 28 ++++++++++++++++++++++------ test/test.parser.js | 14 +++++++++++++- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 940ee6b..52181e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +Added: + +* Allow passing an `Array` of arguments to `Parser#parse()` + Changed: * Replace dependency [minimist](https://github.com/substack/minimist) with diff --git a/README.md b/README.md index cf95a6c..c7f0144 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,10 @@ A `Parser` has these methods: * __epilog__: a string that will appear at the bottom of the help information -* __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 * __Parser#showHelp()__ diff --git a/index.js b/index.js index dbd1231..5496b3e 100644 --- a/index.js +++ b/index.js @@ -23,9 +23,7 @@ var argv = require("yargs-parser"); * @return {Array} arguments */ function processArgv() { - var args = process.argv.slice(); - args.shift(); // node - args.shift(); // filename/command-name + var args = process.argv.slice(2); return args; } @@ -56,7 +54,7 @@ function isFunction(variable) { /** - * Returns `true` if `variable` is a String. Otherwise `false` + * Returns `true` if `variable` is a String. Otherwise `false`. * * @param {*} variable * @return {Boolean} @@ -66,6 +64,17 @@ function isString(variable) { } +/** + * Returns `true` if `variable` is an Array. Otherwise `false`. + * + * @param {*} variable + * @return {Boolean} + */ +function isArray(variable) { + return variable instanceof Array; +} + + /** * Parser * @constructor @@ -199,12 +208,19 @@ Parser.prototype.epilog = function(epilog) { /** * Parses a string for commands - * @param {String} commandString + * @param {String|Array} commandString * @return {Parser} this Parser instance */ Parser.prototype.parse = function parse(cmds) { 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 = { }; var command = args[0]; function exec(target, ctx) { diff --git a/test/test.parser.js b/test/test.parser.js index ef1ed8a..5175487 100644 --- a/test/test.parser.js +++ b/test/test.parser.js @@ -255,7 +255,7 @@ describe("Argument parsing", function() { }); }); - it("should parse args passed in .parse(args)", function(done) { + it("should parse string 'args' passed in .parse(args)", function(done) { var name = "NAME"; var arg1 = "ARG1"; var arg2 = "ARG2"; @@ -267,6 +267,18 @@ describe("Argument parsing", function() { }).parse([name, arg1, arg2].join(" ")); }); + it("should parse array 'args' passed in .parse(args)", function(done) { + var name = "NAME"; + var arg1 = "ARG1"; + var arg2 = "ARG2"; + var parser = new Parser(function() {}); + parser.option(name, "blah", function(someArg, anotherArg) { + someArg.should.equal(arg1); + anotherArg.should.equal(arg2); + done(); + }).parse([name, arg1, arg2]); + }); + it("should bind a this with the args processed by minimist", function(done) { var parser = new Parser(function() { }); parser.option("test", "some test", function(arg1, arg2) { From 47786cd0b223482eae518d4ce0cfa9551cfdd760 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 6 Jun 2016 14:51:30 +0300 Subject: [PATCH 5/9] Update documentation within code --- index.js | 61 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index 5496b3e..ad20b0c 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,11 @@ /* -| simple-argparse -| simple argument parser for command line applications -| -| Author: GochoMugo -| Copyright (c) Forfuture LLC -| License: MIT -*/ + | simple-argparse + | simple argument parser for command line applications + | + | Author: GochoMugo + | Copyright (c) Forfuture LLC + | License: MIT + */ "use strict"; @@ -16,21 +16,19 @@ 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_ * * @return {Array} arguments */ function processArgv() { - var args = process.argv.slice(2); - return args; + return process.argv.slice(2); } /** - * Wraps padding space around some text, specfically by adding spaces - * at the end of text + * Appends padding space to some text. * * @param {String} text * @param {Number} width - width of column @@ -76,7 +74,8 @@ function isArray(variable) { /** - * Parser + * Parser. + * * @constructor * @param {Function} stdout - passed output * @return {Parser} @@ -99,7 +98,8 @@ function Parser(stdout) { /** - * Adds Name and/or Description to the Parser + * Adds Name and/or Description to the Parser. + * * @param {String} [name] * @param {String} text * @return {Parser} this Parser Instance @@ -116,7 +116,8 @@ Parser.prototype.description = function description(name, text) { /** - * Adds Version information + * Adds Version information. + * * @param {String} versionNum * @return {Parser} this Parser instance */ @@ -127,7 +128,8 @@ Parser.prototype.version = function version(versionNum) { /** - * Adds an option/command + * Adds an option/command. + * * @param {String} [alias] * @param {String} command * @param {String} description @@ -169,7 +171,8 @@ Parser.prototype.option = function option(alias, command, description, func) { /** - * 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 * @return {Parser} this Parser instance */ @@ -182,7 +185,7 @@ Parser.prototype.defaultOption = function defaultOption(func) { /** - * Add a pre-run function + * Add a pre-run function. * * @param {Function} func * @return {Parser} this Parser instance @@ -196,7 +199,8 @@ Parser.prototype.prerun = function prerun(func) { /** - * Adds a bottom epilog + * Adds a bottom epilog. + * * @param {String} epilog * @return {Parser} this Parser instance */ @@ -207,8 +211,9 @@ Parser.prototype.epilog = function(epilog) { /** - * Parses a string for commands - * @param {String|Array} commandString + * Parses a string for commands. + * + * @param {String|Array} cmds - commands/args * @return {Parser} this Parser instance */ Parser.prototype.parse = function parse(cmds) { @@ -249,8 +254,9 @@ Parser.prototype.parse = function parse(cmds) { /** - * 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 */ Parser.prototype.showHelp = function showHelp() { @@ -276,8 +282,9 @@ Parser.prototype.showHelp = function showHelp() { /** - * 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 */ Parser.prototype.showVersion = function showVersion() { From 740eda8013ae3558dcc72e83b6078bd8febb561f Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 6 Jun 2016 14:53:24 +0300 Subject: [PATCH 6/9] [maintenance] Update dependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 90d9a2e..f2ef41f 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,9 @@ "grunt-mocha-test": "^0.12.7", "istanbul": "^0.4.3", "load-grunt-tasks": "^3.2.0", - "mocha": "^2.4.5", + "mocha": "^2.5.3", "mocha-lcov-reporter": "^1.2.0", - "should": "^8.3.1" + "should": "^9.0.0" }, "scripts": { "test": "grunt test", From 4325f81600f934d59486fd6c2da1957edd866ca6 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 6 Jun 2016 14:59:22 +0300 Subject: [PATCH 7/9] Test against Node 4.x series Also, remove automated deployment to npm. It just sucks. --- .travis.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index cacb949..2548a2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,8 @@ language: node_js node_js: +- '4' - '0.12' - '0.11' - '0.10' script: npm test after_script: npm run test-coverage && cat ./coverage/lcov.info | coveralls -deploy: - provider: npm - email: mugo@forfuture.co.ke - api_key: - secure: OwPRUPXcE/i7fgo6pE2xmu3rxaloaegsadRiRPtZlPF1bCFbOYqIk33fsWUcohoW2bY4nq1C116sNumWBL1oi0AQg2Sk1nOzRXM4Ysc8rpwGP6HHEcmSsCWSRckvePn8ReO6t394RJzVPZ08SoJ7TwQtcsTMsJlv/Y2w1jJjv5Y= - on: - tags: true - repo: forfutureLLC/node-simple-argparse - branch: master From e87944ee86465724fb6d26b29b5a882277407391 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 6 Jun 2016 15:05:34 +0300 Subject: [PATCH 8/9] Update changelog with missing history/logs --- CHANGELOG.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52181e5..09bdc2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,3 +15,58 @@ Changed: * Replace dependency [minimist](https://github.com/substack/minimist) with [yargs-parser](https://github.com/yargs/yargs-parser) + + +### 0.3.0 - 2015-08-05 + +Added: + +* Allow shorter commands +* Allow pre-run hook + + +### 0.2.2 - 2015-08-03 + +Fixes: + +* Fix error showing help information by default +* Fix typos in package manifest + + +### 0.2.1 - 2015-07-29 + +Fixes: + +* Fix "shasum check failed" error while npm installing + + +### 0.2.0 - 2015-07-29 + +Added: + +* Pass the option name to option functions (issue #2) +* Allow overriding default option function run (issue #3) + + +### 0.1.1 - 2015-07-19 + +Fixed: + +* Fix broken link in documentation + + +### 0.1.0 - 2015-07-19 + + +Changed: + +* The entire code-base has been updated +* The documentation has also been updated +* The license and contact information updated +* Grunt has been added as our task runner +* Linting using eslint + + +### 0.0.0 - 2014-12-22 + +Hello, World! From 723228e5d797109b51e34942c926458e5ad08e71 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 6 Jun 2016 15:06:48 +0300 Subject: [PATCH 9/9] Bump major version: 0.3.0 - 1.0.0 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09bdc2f..ba00bd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### 1.0.0 - 2016-06-06 + Added: * Allow passing an `Array` of arguments to `Parser#parse()` diff --git a/package.json b/package.json index f2ef41f..d084297 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-argparse", - "version": "0.3.0", + "version": "1.0.0", "description": "Simple Argument parser for Command-line Applications", "homepage": "https://github.com/forfutureLLC/node-simple-argparse", "license": "MIT",