Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminlykins committed Sep 6, 2016
1 parent 5fcac8a commit f8839c5
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Expand Up @@ -5,7 +5,8 @@
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
You can make JSON style objects directly from command line arguments using simple notation. Dashes indicate classes,
attributes, and values.
```
$ node add-contact.js person -firstname --john -lastname --smith -age --30
```
Expand All @@ -20,6 +21,9 @@ Would serialize to
}
```
## Usage
Command line arguments with no dashes are the base class(es) or attribute(s). Each dash represents another 'level'. In this example, person is the base class, firstname, lastname, and age are the attributes, and john, smith, and 30 are the values of those attributes.

Levels are determined by the number of dashes before an argument. The fewer dashes the higher the level. Arguments with no levels below them (they have no arguments with more dashes following them in the list) are values. Arguments with only one level after them are attributes. Arguments with multiple levels after them are classes.
```
//$ exampleProgram person -firstname --john -lastname --smith -age --30
Expand All @@ -30,6 +34,27 @@ console.log(params.firstname); //prints john
```

```
//$ exampleProgram2 car -tire --type ---goodyear --age ---2 -color --blue -cost --10000 -condition --good
var cla = require('command-line-arguments');
var params = cla.getCommandLineArguments();
// params = {
// car:{
// tire: {
// type: 'goodyear',
// age: 2
// }
// color: blue,
// cost: 10000,
// condition: 'good'
// }
//}
```

##Install
```
npm install command-line-arguments --save
Expand Down

0 comments on commit f8839c5

Please sign in to comment.