index.js
function getParserConfiguration(target, config) {
  target = target || this;
  config = config || {alias: {}, flags: [], options: []};
  var k, arg, key
    , conf  = this.configure();
  var no = /^\[?no\]?/, nor = /(\[no-?\]-?)/;
  for(k in target._options) {
    arg = target._options[k];

    // misconfigured option, not a valid instance
    if(typeof arg.isArgument !== 'function') continue;

    if(!arg.isFlag() && !arg.isOption()) {
      continue;
    }
    var names = arg.names().slice(0);
    names.forEach(function(nm, index, arr) {
      arr[index] = nm.replace(nor, '');
    })
    key = arg.key();
    //console.log('key: %s', key);
    if(no.test(key)) {
      // this works around an issue with args such as --noop
      // without the charAt test the id is *op*
      // ensuring the first character is uppercase is akin to
      // checking the declaration was '[no]-'
      if(/^[A-Z]$/.test(key.charAt(2))) {
        key = key.replace(no, '');
        key = key.charAt(0).toLowerCase() + key.slice(1);
      }
      //console.log('final key: %s', key);
    }
    config.alias[names.join(' ')] = key;
    if(arg.isFlag()) {
      config.flags = config.flags.concat(names);
    }else{
      config.options = config.options.concat(names);
    }
  }

  // TODO: sometimes child options have the same keys
  // TODO: as top-level options, these duplicates can be removed
  for(k in target._commands) {
    getParserConfiguration.call(this, target._commands[k], config);
  }

  if(conf.variables && conf.variables.prefix) {
    config.vars = {variables: conf.variables.prefix};
  }

  return config;
}
function getParserConfiguration(target, config) {
  target = target || this;
  config = config || {alias: {}, flags: [], options: []};
  var k, arg, key
    , conf  = this.configure();
  var no = /^\[?no\]?/, nor = /(\[no-?\]-?)/;
  for(k in target._options) {
    arg = target._options[k];

    // misconfigured option, not a valid instance
    if(typeof arg.isArgument !== 'function') continue;

    if(!arg.isFlag() && !arg.isOption()) {
      continue;
    }
    var names = arg.names().slice(0);
    names.forEach(function(nm, index, arr) {
      arr[index] = nm.replace(nor, '');
    })
    key = arg.key();
    //console.log('key: %s', key);
    if(no.test(key)) {
      // this works around an issue with args such as --noop
      // without the charAt test the id is *op*
      // ensuring the first character is uppercase is akin to
      // checking the declaration was '[no]-'
      if(/^[A-Z]$/.test(key.charAt(2))) {
        key = key.replace(no, '');
        key = key.charAt(0).toLowerCase() + key.slice(1);
      }
      //console.log('final key: %s', key);
    }
    config.alias[names.join(' ')] = key;
    if(arg.isFlag()) {
      config.flags = config.flags.concat(names);
    }else{
      config.options = config.options.concat(names);
    }
  }

  // TODO: sometimes child options have the same keys
  // TODO: as top-level options, these duplicates can be removed
  for(k in target._commands) {
    getParserConfiguration.call(this, target._commands[k], config);
  }

  if(conf.variables && conf.variables.prefix) {
    config.vars = {variables: conf.variables.prefix};
  }

  return config;
}
function getParserConfiguration ( target , config ) { target = target || this ; config = config || { alias : { } , flags : [ ] , options : [ ] } ; var k , arg , key , conf = this . configure ( ) ; var no = / ^\[?no\]? / , nor = / (\[no-?\]-?) / ; for ( k in target . _options ) { arg = target . _options [ k ] ; // misconfigured option, not a valid instance if ( typeof arg . isArgument !== 'function' ) continue ; if ( ! arg . isFlag ( ) && ! arg . isOption ( ) ) { continue ; } var names = arg . names ( ) . slice ( 0 ) ; names . forEach ( function ( nm , index , arr ) { arr [ index ] = nm . replace ( nor , '' ) ; } ) key = arg . key ( ) ; //console.log('key: %s', key); if ( no . test ( key ) ) { // this works around an issue with args such as --noop // without the charAt test the id is *op* // ensuring the first character is uppercase is akin to // checking the declaration was '[no]-' if ( / ^[A-Z]$ / . test ( key . charAt ( 2 ) ) ) { key = key . replace ( no , '' ) ; key = key . charAt ( 0 ) . toLowerCase ( ) + key . slice ( 1 ) ; } //console.log('final key: %s', key); } config . alias [ names . join ( ' ' ) ] = key ; if ( arg . isFlag ( ) ) { config . flags = config . flags . concat ( names ) ; } else { config . options = config . options . concat ( names ) ; } } // TODO: sometimes child options have the same keys // TODO: as top-level options, these duplicates can be removed for ( k in target . _commands ) { getParserConfiguration . call ( this , target . _commands [ k ] , config ) ; } if ( conf . variables && conf . variables . prefix ) { config . vars = { variables : conf . variables . prefix } ; } return config ; }
Retrieve a configuration suitable for passing to
the arguments parser.
Retrieve a configuration suitable for passing to the arguments parser .