mirror of
https://github.com/flynx/argv.js.git
synced 2025-12-27 05:41:57 +00:00
started work on docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
62fc0f62d5
commit
56bd50ae7d
76
README.md
76
README.md
@ -1,12 +1,9 @@
|
||||
# ig-argv
|
||||
# argv.js
|
||||
|
||||
simple argv parser
|
||||
|
||||
**Note:** this is still a work in progress, more and better docs are
|
||||
coming and the code is still evolving...
|
||||
Simple argv parser
|
||||
|
||||
|
||||
# Motivation
|
||||
## Motivation
|
||||
|
||||
I needed a new argv parser for a quick and dirty project I was working on
|
||||
and evaluating and selecting the propper existing parser and then learining its
|
||||
@ -16,3 +13,70 @@ myself in a couple of hours.
|
||||
This code is an evolution of that parser.
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
- Simple
|
||||
- Supports both the _option_ (a-la `find`) and _command_ (a-la `git`) paradigms
|
||||
- Nestable – parsers can be nested as option/command handlers defining
|
||||
independent nested contexts
|
||||
- Option expansion – `-abc` expands to `-a -b -c` if `-abc` is not defined
|
||||
- Option/command value passing
|
||||
- Environment variable option/command values – env can control option
|
||||
defaults
|
||||
- Reasonable defaults
|
||||
- `-help` generator
|
||||
- common option aliases
|
||||
- Extensible:
|
||||
- Hooks for option value conversion _(XXX should this be implemented???)_
|
||||
- Hooks for dynamic option/command handling
|
||||
- Customizable error and stop condition handling
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
$ npm install ig-argv
|
||||
```
|
||||
|
||||
## Basic usage
|
||||
|
||||
Create a script and make it runnable
|
||||
```shell
|
||||
$ toch script.js
|
||||
$ chmod +x script.js
|
||||
```
|
||||
|
||||
Now for the code
|
||||
```javascript
|
||||
#!/usr/bin/env node
|
||||
|
||||
// compatible with both node's and RequireJS' require(..)
|
||||
var argv = require('ig-argv')
|
||||
|
||||
var parser = argv.Parser({
|
||||
// XXX
|
||||
})
|
||||
.then(function(){
|
||||
// XXX
|
||||
})
|
||||
|
||||
// run the parser only if script.js is run directly...
|
||||
if(__filename == require.main){
|
||||
parser(process.argv) }
|
||||
```
|
||||
|
||||
This will create a parser that supports the folowing:
|
||||
```shell
|
||||
$ ./script.js --help
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[BSD 3-Clause License](./LICENSE)
|
||||
|
||||
Copyright (c) 2016-2020, Alex A. Naanou,
|
||||
All rights reserved.
|
||||
|
||||
|
||||
<!-- vim:set ts=4 sw=4 spell : -->
|
||||
5
argv.js
5
argv.js
@ -105,8 +105,8 @@ var afterCallbackCall = function(name, context, ...args){
|
||||
// yet know of any error or stop conditions triggered later in the argv.
|
||||
//
|
||||
//
|
||||
// XXX add merged options...
|
||||
// -a -b -c -> -abc
|
||||
// XXX add support for - or -- stdin handling... (???)
|
||||
// XXX add support for outputting strings instead of console.log(..)
|
||||
// XXX --help should work for any command and not just for the nested
|
||||
// parser commands... (???)
|
||||
// ...not sure how to implement this...
|
||||
@ -346,6 +346,7 @@ object.Constructor('Parser', {
|
||||
// NOTE: this is mainly needed to handle dynamic arguments or print
|
||||
// error on unknown options (default)...
|
||||
handleArgument: function(_, key){
|
||||
// doc handler...
|
||||
if(arguments.length == 1 && arguments[0] == 'doc'){
|
||||
return undefined }
|
||||
console.error('Unknown '+ (key.startsWith('-') ? 'option:' : 'command:'), key)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-argv",
|
||||
"version": "2.0.4",
|
||||
"version": "2.0.5",
|
||||
"description": "simple argv parser",
|
||||
"main": "argv.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user