-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See CHANGELOG.md
- Loading branch information
Showing
7 changed files
with
159 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: [email protected] | ||
api_key: | ||
secure: OwPRUPXcE/i7fgo6pE2xmu3rxaloaegsadRiRPtZlPF1bCFbOYqIk33fsWUcohoW2bY4nq1C116sNumWBL1oi0AQg2Sk1nOzRXM4Ysc8rpwGP6HHEcmSsCWSRckvePn8ReO6t394RJzVPZ08SoJ7TwQtcsTMsJlv/Y2w1jJjv5Y= | ||
on: | ||
tags: true | ||
repo: forfutureLLC/node-simple-argparse | ||
branch: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
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()` | ||
|
||
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014-2015 Forfuture LLC <[email protected]> | ||
Copyright (c) 2014-2016 Forfuture LLC <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -94,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()__ | ||
|
@@ -114,7 +118,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 +181,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__. | ||
|
@@ -187,7 +191,7 @@ be ignored. This may be useful for commands __not yet implemented__. | |
|
||
__The MIT License (MIT)__ | ||
|
||
Copyright (c) 2014-2015 Forfuture LLC <[email protected]> | ||
Copyright (c) 2014-2016 Forfuture LLC <[email protected]> | ||
|
||
|
||
[minimist]:https://github.com/substack/minimist | ||
[argv]:https://github.com/yargs/yargs-parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
/* | ||
| simple-argparse | ||
| simple argument parser for command line applications | ||
| | ||
| Author: GochoMugo <[email protected]> | ||
| Copyright (c) Forfuture LLC <[email protected]> | ||
| License: MIT | ||
*/ | ||
| simple-argparse | ||
| simple argument parser for command line applications | ||
| | ||
| Author: GochoMugo <[email protected]> | ||
| Copyright (c) Forfuture LLC <[email protected]> | ||
| License: MIT | ||
*/ | ||
|
||
|
||
"use strict"; | ||
|
||
|
||
// 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_ | ||
* | ||
* @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); | ||
} | ||
|
||
|
||
/** | ||
* 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 | ||
|
@@ -56,7 +52,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} | ||
|
@@ -67,7 +63,19 @@ function isString(variable) { | |
|
||
|
||
/** | ||
* Parser | ||
* Returns `true` if `variable` is an Array. Otherwise `false`. | ||
* | ||
* @param {*} variable | ||
* @return {Boolean} | ||
*/ | ||
function isArray(variable) { | ||
return variable instanceof Array; | ||
} | ||
|
||
|
||
/** | ||
* Parser. | ||
* | ||
* @constructor | ||
* @param {Function} stdout - passed output | ||
* @return {Parser} | ||
|
@@ -90,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 | ||
|
@@ -107,7 +116,8 @@ Parser.prototype.description = function description(name, text) { | |
|
||
|
||
/** | ||
* Adds Version information | ||
* Adds Version information. | ||
* | ||
* @param {String} versionNum | ||
* @return {Parser} this Parser instance | ||
*/ | ||
|
@@ -118,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 | ||
|
@@ -160,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 | ||
*/ | ||
|
@@ -173,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 | ||
|
@@ -187,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 | ||
*/ | ||
|
@@ -198,13 +211,21 @@ Parser.prototype.epilog = function(epilog) { | |
|
||
|
||
/** | ||
* Parses a string for commands | ||
* @param {String} commandString | ||
* Parses a string for commands. | ||
* | ||
* @param {String|Array} cmds - commands/args | ||
* @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) { | ||
|
@@ -233,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() { | ||
|
@@ -260,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() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
|
@@ -21,7 +21,7 @@ | |
"author": "GochoMugo <[email protected]>", | ||
"main": "index.js", | ||
"dependencies": { | ||
"minimist": "^1.1.2" | ||
"yargs-parser": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^2.11.3", | ||
|
@@ -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", | ||
|
Oops, something went wrong.