Alex A. Naanou c62be60010 typo fix...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2020-07-01 03:12:55 +03:00
2020-07-01 03:09:23 +03:00
2020-06-13 23:09:14 +03:00
2020-07-01 03:09:23 +03:00
2020-07-01 03:12:55 +03:00
2020-06-29 16:24:40 +03:00

argv.js

Simple argv parser

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 API, quirks and adapting the architecture to it seemd to be more complicated, require more effort and far less fun than putting together a trivial parser 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

$ npm install ig-argv

Basic usage

Create a script and make it runnable

$ touch script.js
$ chmod +x script.js

Now for the code

#!/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:

$ ./script.js --help 

License

BSD 3-Clause License

Copyright (c) 2016-2020, Alex A. Naanou,
All rights reserved.

Languages
JavaScript 100%