obj/Release/Package/PackageTmp/build/node_modules/argh/index.js

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

'use strict';

/**
 * Argv is a extremely light weight options parser for Node.js it's been built
 * for just one single purpose, parsing arguments. It does nothing more than
 * that.
 *
 * @param {Array} argv The arguments that need to be parsed, defaults to process.argv
 * @returns {Object} Parsed arguments.
 * @api public
 */
function parse(argv) {
  argv = argv || process.argv.slice(2);

  /**
   * This is where the actual parsing happens, we can use array#reduce to
   * iterate over the arguments and change it to an object. We can easily bail
   * out of the loop by destroying `argv` array.
   *
   * @param {Object} argh The object that stores the parsed arguments
   * @param {String} option The command line flag
   * @param {Number} index The position of the flag in argv's
   * @param {Array} argv The argument variables
   * @returns {Object} argh, the parsed commands
   * @api private
   */
  return argv.reduce(function parser(argh, option, index, argv) {
    var next = argv[index + 1]
      , value
      , data;

    //
    // Special case, -- indicates that it should stop parsing the options and
    // store everything in a "special" key.
    //
    if (option === '--') {
      //
      // By splicing the argv array, we also cancel the reduce as there are no
      // more options to parse.
      //
      argh.argv = argh.argv || [];
      argh.argv = argh.argv.concat(argv.splice(index + 1));
      return argh;
    }

    if (data = /^--?(?:no|disable)-(.*)/.exec(option)) {
      //
      // --no-<key> indicates that this is a boolean value.
      //
      insert(argh, data[1], false, option);
    } else if (data = /^-(?!-)(.*)/.exec(option)) {
      insert(argh, data[1], true, option);
    } else if (data = /^--([^=]+)=\W?([\w\-\.\/]+)\W?$/.exec(option)) {
      //
      // --foo="bar" and --foo=bar are alternate styles to --foo bar.
      //
      insert(argh, data[1], data[2], option);
    } else if (data = /^--(.*)/.exec(option)) {
      //
      // Check if this was a bool argument
后面还有 77 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。