mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-28 18:30:07 +00:00
bugfix...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e3a3ce19f3
commit
75e57c6553
30
argv.js
30
argv.js
@ -465,17 +465,31 @@ object.Constructor('Parser', {
|
|||||||
1
|
1
|
||||||
: ai - bi })
|
: ai - bi })
|
||||||
.map(function([e, _]){ return e }) },
|
.map(function([e, _]){ return e }) },
|
||||||
optionsWithValue: function(){
|
optionsWithValue: function(selector='optoins'){
|
||||||
return this.options()
|
return this[selector]()
|
||||||
.filter(function([k, a, d, handler]){
|
.filter(function([k, a, d, handler]){
|
||||||
return !!handler.env
|
return !!handler.env
|
||||||
|| 'default' in handler }) },
|
|| 'default' in handler }) },
|
||||||
requiredOptions: function(){
|
requiredOptions: function(selector='optoins'){
|
||||||
return this.options()
|
return this[selector]()
|
||||||
.filter(function([k, a, d, handler]){
|
.filter(function([k, a, d, handler]){
|
||||||
return handler.required }) },
|
return handler.required }) },
|
||||||
|
|
||||||
commands: function(){
|
commands: function(){
|
||||||
return this.options(COMMAND_PREFIX) },
|
return this.options(COMMAND_PREFIX) },
|
||||||
|
commandsWithValue: function(){
|
||||||
|
return this.optionsWithValue('commands') },
|
||||||
|
requiredCommands: function(){
|
||||||
|
return this.requiredOptions('commands') },
|
||||||
|
|
||||||
|
// XXX might be a good idea to make this the base and derive the rest from here...
|
||||||
|
// XXX a better name???
|
||||||
|
allArguments: function(){
|
||||||
|
return this.options(OPTION_PREFIX, COMMAND_PREFIX) },
|
||||||
|
argumentsWithValue: function(){
|
||||||
|
return this.optionsWithValue('allArguments') },
|
||||||
|
requiredArguments: function(){
|
||||||
|
return this.requiredOptions('allArguments') },
|
||||||
|
|
||||||
// Get handler...
|
// Get handler...
|
||||||
//
|
//
|
||||||
@ -713,6 +727,8 @@ object.Constructor('Parser', {
|
|||||||
...getValue('doc'),
|
...getValue('doc'),
|
||||||
// options...
|
// options...
|
||||||
// XXX add option groups...
|
// XXX add option groups...
|
||||||
|
// ....or: 'Group title': 'section', items that
|
||||||
|
// print as section titles...
|
||||||
...section('Options',
|
...section('Options',
|
||||||
this.options()
|
this.options()
|
||||||
.filter(function([o, a, doc]){
|
.filter(function([o, a, doc]){
|
||||||
@ -808,7 +824,7 @@ object.Constructor('Parser', {
|
|||||||
|
|
||||||
'-v': '-version',
|
'-v': '-version',
|
||||||
'-version': {
|
'-version': {
|
||||||
doc: 'show $SCRIPTNAME verion and exit',
|
doc: 'show $SCRIPTNAME version and exit',
|
||||||
priority: 99,
|
priority: 99,
|
||||||
handler: function(){
|
handler: function(){
|
||||||
this.quiet = false
|
this.quiet = false
|
||||||
@ -1190,7 +1206,7 @@ object.Constructor('Parser', {
|
|||||||
try{
|
try{
|
||||||
// parse/interpret the arguments and call handlers...
|
// parse/interpret the arguments and call handlers...
|
||||||
var values = new Map(
|
var values = new Map(
|
||||||
parsed.optionsWithValue()
|
parsed.argumentsWithValue()
|
||||||
.map(function([k, a, d, handler]){
|
.map(function([k, a, d, handler]){
|
||||||
return [handler, k[0]] }))
|
return [handler, k[0]] }))
|
||||||
var seen = new Set()
|
var seen = new Set()
|
||||||
@ -1260,7 +1276,7 @@ object.Constructor('Parser', {
|
|||||||
|
|
||||||
// check and report required options...
|
// check and report required options...
|
||||||
var missing = parsed
|
var missing = parsed
|
||||||
.requiredOptions()
|
.requiredArguments()
|
||||||
.filter(function([k, a, d, h]){
|
.filter(function([k, a, d, h]){
|
||||||
return !seen.has(h) })
|
return !seen.has(h) })
|
||||||
.map(function([k, a, d, h]){
|
.map(function([k, a, d, h]){
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-argv",
|
"name": "ig-argv",
|
||||||
"version": "2.15.1",
|
"version": "2.15.3",
|
||||||
"description": "simple argv parser",
|
"description": "simple argv parser",
|
||||||
"main": "argv.js",
|
"main": "argv.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user