Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
readme mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
harthur committed Apr 15, 2011
1 parent 9db84a8 commit 80a9cde
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions README.md
Expand Up @@ -21,6 +21,7 @@ nomnom is an option parser for node and CommonJS. It just noms your args and giv
// do stuff // do stuff


You don't even have to specify anything if you don't want to: You don't even have to specify anything if you don't want to:

var options = nomnom.parseArgs(); var options = nomnom.parseArgs();


var url = options[0]; // get the first positional arg var url = options[0]; // get the first positional arg
Expand All @@ -29,11 +30,11 @@ You don't even have to specify anything if you don't want to:


# Install # Install
for [node.js](http://nodejs.org/) and [npm](http://github.com/isaacs/npm): for [node.js](http://nodejs.org/) and [npm](http://github.com/isaacs/npm):

npm install nomnom npm install nomnom


# Commands # Commands
Nomnom supports command-based interfaces, e.g. with git: `git add -p` and Nomnom supports command-based interfaces, e.g. with git: `git add -p` and `git rebase -i` where `add` and `rebase` are the commands:
`git rebase -i` where `add` and `rebase` are the commands:


var parser = nomnom(); var parser = nomnom();


Expand Down Expand Up @@ -62,32 +63,36 @@ Nomnom supports command-based interfaces, e.g. with git: `git add -p` and


# More Details # More Details
By default, nomnom parses [node](http://nodejs.org/)'s `process.argv`. You can also pass in the args: By default, nomnom parses [node](http://nodejs.org/)'s `process.argv`. You can also pass in the args:

var options = nomnom.parseArgs(opts, { argv: ["-xvf", "--atomic=true"] }) var options = nomnom.parseArgs(opts, { argv: ["-xvf", "--atomic=true"] })


Values are JSON parsed, so `--debug=true --count=3 --file=log.txt` would give you: Values are JSON parsed, so `--debug=true --count=3 --file=log.txt` would give you:

{ debug: true, { debug: true,
count: 3, count: 3,
file: "log.txt" file: "log.txt"
} }


### positional args ### positional args
All parsed arguments that don't fit the `-a` or `--atomic` format and aren't attached to an option are positional and can be matched on via the `position`: All parsed arguments that don't fit the `-a` or `--atomic` format and aren't attached to an option are positional and can be matched on via the `position`:

var opts = { var opts = {
filename: { filename: {
position: 0, position: 0,
help: 'file to edit' help: 'file to edit'
} }
}; };
var options = nomnom(opts).parseArgs(); var options = nomnom.parseArgs(opts);


sys.puts(options.filename); sys.puts(options.filename);


### printing usage ### printing usage
Nomnom prints out a usage message if `--help` or `-h` is an argument. You can disable this with the `printHelp` flag and specify the printing function with `printFunc`: Nomnom prints out a usage message if `--help` or `-h` is an argument. You can disable this with the `printHelp` flag and specify the printing function with `printFunc`:


nomnom(opts, { printHelp: false }).parseArgs(); nomnom.parseArgs(opts, { printHelp: false });


Usage for these options in `test.js`: Usage for these options in `test.js`:

var options = { var options = {
command: { command: {
position: 0, position: 0,
Expand All @@ -104,6 +109,7 @@ Usage for these options in `test.js`:
} }


...would look like this: ...would look like this:

Usage: node test.js <command> [options] Usage: node test.js <command> [options]


<command> either 'test', 'run', or 'xpi' <command> either 'test', 'run', or 'xpi'
Expand All @@ -113,4 +119,5 @@ Usage for these options in `test.js`:
-d, --debug use debug mode -d, --debug use debug mode


Nomnom can't detect the alias used to run your script. You can use the `script` option to print the correct name instead of e.g. `node test.js`: Nomnom can't detect the alias used to run your script. You can use the `script` option to print the correct name instead of e.g. `node test.js`:
nomnom(opts, { script : "test" });
nomnom.parseArgs(opts, { script : "test" });

0 comments on commit 80a9cde

Please sign in to comment.