Skip to content

Commit

Permalink
Changed primary function in command-line-arguments and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminlykins committed Aug 29, 2016
1 parent 33e7bdb commit e5a5401
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/BenjaminLykins/command-line-arguments.svg?branch=master)](https://travis-ci.org/BenjaminLykins/command-line-arguments)
[![Coverage Status](https://coveralls.io/repos/github/BenjaminLykins/command-line-arguments/badge.svg?branch=master)](https://coveralls.io/github/BenjaminLykins/command-line-arguments?branch=master)
# command-line-arguments
Serialize JavaScript objects from command line arguments
Simple way to serialize JavaScript objects from command line arguments

## Synopsis
You can make JSON style objects directly from command line arguments using the simple notation
Expand All @@ -20,6 +20,7 @@ Would serialize to
## Usage
```
//$ exampleProgram person -firstname --john -lastname --smith
var cla = require('command-line-arguments');
var params = cla.getGetCommandLineArguments(process.argv.slice(2,process.argv.length));
Expand All @@ -35,15 +36,40 @@ npm install command-line-arguments --save

```
//$ node addFood.js name -hotdog calories -400 primary-ingredients -bun -dog -mustard -ketchup
var food = require('command-line-arguments');
var cla = require('command-line-arguments');
food = cla.getCommandLineArguments();
// food =
// {
// name: 'hotdog',
// calories: '400',
// 'primary-ingredients': [ 'bun', 'dog', 'mustard', 'ketchup' ]
// };
```

```
//$ node nouns.js person place thing
var cla = require('command-line-arguments');
var nouns = cla.getCommandLineArguments();
// nouns = ['person', 'place', 'thing'];
```

```
//$ node program.js
var params = ['car', '-model', '--2001 Toyota Corolla', '-milage', '--219,000', '-color', '--tan' ];
var paramsParsed = cla.getCommandLineArguments(params);
// paramsParsed = {
// car: {
// model: '2001 Toyota Corolla',
// milage: '219,000',
// color: 'tan'
// }
//}
```

##Licensing
Expand Down
4 changes: 2 additions & 2 deletions lib/command-line-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function getGetCommandLineArguments(params){
return recurse(params);
}

function getGetCommandLineArguments(params){
function getCommandLineArguments(params){
if(typeof params === 'undefined')
params = process.argv.slice(2,process.argv.length);
params = validateInput(params);
Expand All @@ -138,5 +138,5 @@ function getGetCommandLineArguments(params){


module.exports = {
getGetCommandLineArguments: getGetCommandLineArguments
getCommandLineArguments: getCommandLineArguments
}
12 changes: 6 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var cla = require('../index.js');

describe('#command-line-arguments', function() {
it('#Standard Test', function() {
var result = cla.getGetCommandLineArguments(['person', '-firstname', '--Benjamin', '-lastname', '--Lykins', '-birthday', '--7/1/95']);
var result = cla.getCommandLineArguments(['person', '-firstname', '--Benjamin', '-lastname', '--Lykins', '-birthday', '--7/1/95']);
var expected = {
person: {
firstname: 'Benjamin',
Expand All @@ -16,9 +16,9 @@ describe('#command-line-arguments', function() {
expect(result).to.deep.equal(expected);
});


it('#Test Using Arrays', function(){
var result = cla.getGetCommandLineArguments(['FavoriteThings', '-sports', '--basketball', '--baseball', '--football',
var result = cla.getCommandLineArguments(['FavoriteThings', '-sports', '--basketball', '--baseball', '--football',
'-languages', '--JavaScript', '--Python', '--HTML']);
var expected = {
FavoriteThings: {
Expand All @@ -31,21 +31,21 @@ describe('#command-line-arguments', function() {


it('#Empty List', function(){
var result = cla.getGetCommandLineArguments([]);
var result = cla.getCommandLineArguments([]);
var expected = [];
expect(result).to.deep.equal(expected);
});


it('#Single Level Object Test', function() {
var result = cla.getGetCommandLineArguments(['lions', 'tigers','bears']);
var result = cla.getCommandLineArguments(['lions', 'tigers','bears']);
var expected = ['lions', 'tigers','bears'];
expect(result).to.deep.equal(expected);
});


it('#Bad Inputs', function(){
var result = cla.getGetCommandLineArguments(['person', '-firstname', '--Benjamin', '----badinput', '-lastname', '--Lykins', '-birthday', '--7/1/95']);
var result = cla.getCommandLineArguments(['person', '-firstname', '--Benjamin', '----badinput', '-lastname', '--Lykins', '-birthday', '--7/1/95']);
var expected = {
person: {
firstname: 'Benjamin',
Expand Down

0 comments on commit e5a5401

Please sign in to comment.