The function that actually invokes the command. Optimist is being used here to parse the array arguments that were provided to your command, however you can use whatever utility you want
485462
function(session, args, callback) {

        // Parse the arguments using optimist
        var argv = optimist.parse(args);

        // Update the environment to indicate who the specified user now is
        session.env('me', argv._[0] || 'unknown');

        // The callback always needs to be invoked to finish the command
        return callback();
    }
862872
function parse (argv, opts, target) {
  if ('string' === typeof argv) argv = argv.split(rSplit).filter(ignore);
  if (!opts) opts = {};
  opts[don] = true;
  var parsed = parseArray(argv, opts);
  opts[don] = false;
  var through = parsed[don].length ? parseArray(parsed[don], opts) : null;
  if (!target) target = {};
  target.options = parsed;
  target.commands = parsed[din];
  target.input = argv;
  if (through) {
    target.through = {
      options: through,
      commands: through[din]
    };
    delete through[din];
  }
  delete parsed[din];
  delete parsed[don];
  return target;
  function ignore (s) {
    return s && '' !== s;
  }
}
332764
function runTool(platform, args_, done) {
  var args = optimist.argv;
  var allzones = args['allzones'];

  var inputFile = args['_'][0];
  if (!inputFile) {
    console.log('usage: dump.js [--allzones] file.wtf-trace');
    done(1);
    return;
  }
  console.log('Dumping ' + inputFile + '...');
  console.log('');

  wtf.db.load(inputFile, function(db) {
    if (db instanceof Error) {
      console.log('ERROR: unable to open ' + inputFile, db, db.stack);
      done(1);
    } else {
      done(dumpDatabase(db, allzones));
    }
  });
}
1340448
function invoke(argv_, fn, msg) {
  var argv = argv_;

  if (_.isFunction(argv.getParams)) {
    argv = argv.getParams({});
  }

  if (argv.ra_file) {
    let jsonfile = argv.ra_file;
    argv = require(jsonfile);
  }

  var params    = {};
  params.params = _.omit(argv, 'args');

  _.each(argv.args, function(arg, n) {
    params.params['arg'+n] = arg;
  });

  var spec      = {};
  return ra.invoke(params, spec, fn, function(err) {
    var exitCode = 0;

    if (err) {
      exitCode = 1;
      console.error(err, "Error invoking: "+msg);
    }

    if (arguments.length === 1) {
      process.exit(exitCode);
      return;
    }

    if (arguments.length === 2) {
      if (_.isString(arguments[1])) {
        process.stdout.write(arguments[1]+'\n');
      } else {
        process.stdout.write(JSON.stringify(arguments[1])+'\n');
      }
      return;
    }

    /* otherwise */
    process.stdout.write(JSON.stringify(_.rest(arguments))+'\n');
    process.exit(exitCode);
  });
}
746976
function GetCommandList(execName, packageJson, Commands) {
  const header = `\
${packageJson.title || packageJson.name || execName} ${packageJson.version}
Usage:    ${execName} ${col.bold('<command>')} [options]
Commands:`;

  const grouped = _.groupBy(Commands, 'helpGroup');
  const sorted = _.mapValues(grouped, arr => _.sortBy(arr, 'helpPriority'));
  const sortedGroups = _.sortBy(sorted, grp => grp[0].helpPriority);
  const longestCmd = _.max(_.map(Commands, cmd => cmd.name.length));
  const commandListStr = _.map(sortedGroups, (helpGroup) => {
    const groupName = _.first(helpGroup).helpGroup;
    return _.flatten([
      `\n  * ${col.primary(groupName)}`,
      _.map(helpGroup, (cmd) => {
        const cmdName = _.padEnd(cmd.name, longestCmd);
        return `    ${col.bold(cmdName)} ${cmd.desc}`;
      }),
    ]).join('\n');
  }).join('\n');

  return `\
${header}
${commandListStr}

Use ${col.bold(`${execName} <command> -h`)} for command-specific help.`;
}
774466
function prepare_command(input_args) {

  let command = null;
  const args = Array.prototype.slice.call(input_args);
  const funcOrCommand = args.shift();

  if (is(funcOrCommand, Command))
    command = funcOrCommand;

  if (is(funcOrCommand, Function))
    command = new Command(funcOrCommand);

  if (!command)
    throw new Error(Errors.BadExecuteArgument);

  command.arguments = args;
  command.result_file = null;

  return command;

}
62437
function parseArguments() {
    var aFileList;

    if (g_aInput.length > 0) {
        aFileList = g_aInput;
    } else {
        aFileList = process.argv;
    }

    Commander.parse(aFileList);
    if (g_aInput.length === 0 && (Commander.args && Commander.args.length === 0)) {
        process.exitCode = EXIT_ERROR_NO_PATH_GIVEN;
        console.error(Chalk.red('Error: ') + Chalk.bold(' no path given'));
        Commander.outputHelp();
    }
}
271468
function ParseArguments(cmd, args) {
  assert(_.isObject(cmd), 'require an object argument for "cmd".');
  assert(_.isObject(args), 'require an object argument for "args".');
  const argSpec = cmd.argSpec || [];
  const cmdName = cmd.name;

  //
  // Build a map of all flag aliases.
  //
  const allAliases = _.fromPairs(_.map(_.flatten(_.map(argSpec, 'flags')), (flagAlias) => {
    return [flagAlias, true];
  }));

  //
  // Make sure all provided flags are specified in the argSpec.
  //
  _.forEach(args, (argVal, argKey) => {
    if (argKey === '_') return; // ignore positional arguments
    if (!(argKey in allAliases)) {
      const d = argKey.length === 1 ? '-' : '--';
      throw new Error(
        `Unknown command-line option "${col.bold(d + argKey)}" specified ` +
        `for command "${col.bold(cmdName)}".`);
    }
  });

  //
  // Handle boolean flags specified as string values on the command line.
  //
  args = _.mapValues(args, (flagVal) => {
    if (_.isString(flagVal)) {
      if (flagVal === 'true') {
        return true;
      }
      if (flagVal === 'false') {
        return false;
      }
    }
    return flagVal;
  });

  //
  // For each flag in the argSpec, see if any alias of the flag is
  // present in `args`. If it is, then assign that value to *all*
  // aliases of the flag. If it is not present, then assign the
  // default value. Throw on unspecified required flags.
  //
  const finalFlags = {};
  _.forEach(argSpec, (aspec, idx) => {
    // Find the first alias of this flag that is specified in args, if at all.
    const foundAlias = _.find(aspec.flags, (flagAlias) => {
      return flagAlias && (flagAlias in args);
    });
    let assignValue = foundAlias ? args[foundAlias] : (aspec.defVal || aspec.default);

    // If defVal is an object, then we need to execute a function to get the
    // default value.
    if (_.isObject(assignValue)) {
      assert(
        _.isFunction(assignValue.fn),
        `Argspec entry ${idx} has an invalid 'defVal'/'default' property.`);
      assignValue = assignValue.fn.call(argSpec);
    }

    if (!_.isUndefined(assignValue)) {
      // Assign value to all aliases of flag.
      _.forEach(aspec.flags, (flagAlias) => {
        finalFlags[flagAlias] = assignValue;
      });
    }
  });

  // Copy positional arguments to finalFlags.
  finalFlags._ = args._;

  return finalFlags;
}
156057
function optimizeNestedIifes(node) {
  var ok =
    matches({
      type: "ReturnStatement",
      argument: {
        type: "CallExpression",
        callee: {
          type: "FunctionExpression",
          body: {}
        }
      }
    })(node) &&
    get(node, "argument.arguments.length") === 0 &&
    get(node, "argument.callee.params.length") === 0 &&
    get(node, "argument.callee.body.body.length") === 1 &&
    get(node, "argument.callee.body.body[0].type") === "ReturnStatement";
  if (ok) {
    var kidNode = node.argument.callee.body.body[0];
    estraverse.replace(kidNode, {enter: optimizeNestedIifes});
    return kidNode;
  }
}
1255645
function interpret(rawArgs) {
		// Determine if we're using stdin or files
		var argv = require('minimist')(rawArgs.slice(2));

		// Construct mocha arguments
		// XXXX accept other mocha opts
		var mochaOpts = {
			// grep: '',
			// ui: '',
			// timeout: '',
			// bail: '',
			reporter: argv.R || argv.reporter
		};

		// File-based input
		if (argv._.length > 0) {
			for (var i = argv._.length - 1; i >= 0; i--) {
				var data = fs.readFileSync(argv._[i], 'utf8');
				testDocument(data, mochaOpts);
			}
		} else { // Attempt to use STDIN
			stdin(function(data) {
				testDocument(data, mochaOpts);
			});
		}
	}
1010478
@SuppressWarnings("unchecked")
  public final Command optimiezeGet(final Queue writeQueue, final Queue<Command> executingCmds,
      Command optimiezeCommand) {
    if (optimiezeCommand.getCommandType() == CommandType.GET_ONE
        || optimiezeCommand.getCommandType() == CommandType.GETS_ONE) {
      if (this.optimiezeGet) {
        optimiezeCommand = this.mergeGetCommands(optimiezeCommand, writeQueue, executingCmds,
            optimiezeCommand.getCommandType());
      }
    }
    return optimiezeCommand;
  }
562050
function(command, arg) {
    if (!arg) {
      arg = 'default';
    }

    if (!commands[command]) {
      grunt.fail.fatal('Command [' + command + '] not found.');
    }

    // Check arg
    if (typeof (commands[command]) !== 'function') {
      if (!commands[command][arg]) {
        grunt.fail.fatal('Argument [' + arg + '] for [' + command
            + '] not found.');
      }
    }

    var func = (arg) ? commands[command][arg] : commands[command];
    if (!func) {
      func = commands[command]; // fallback to the main function
    }

    var options = this.options();
    var docker = (options.docker) ? new Docker(options.docker) : null;
    var done = this.async();

    var callback = function(e) {
      if (e) {
        grunt.fail.warn(e);
      }
      done();
    };

    func.apply(this, [ grunt, docker, options, callback, arg ]);
  }
847637
function cli(args) {
    const { _: [command] } = args;
    return getModule(command).default(args)
        .catch(err => {
            getModule('input').emitError(err.message);
            process.exit(1);
        });
}
1011382
function GetCommandUsage(execName, packageJson, cmdSpec, args) {
  const argSpec = cmdSpec.argSpec || [];
  const optStr = argSpec.length ? ' [options]' : '';
  const header = `\
Usage:   ${execName} ${cmdSpec.name}${optStr}
Purpose: ${cmdSpec.desc}
Options: ${argSpec.length ? '' : 'none.'}`;

  const usageTableRows = _.map(cmdSpec.argSpec, (argDef) => {
    const dashify = flag => (flag.length === 1 ? `-${col.primary(flag)}` : `--${col.primary(flag)}`);
    const lhs = _.map(argDef.flags, dashify).join(', ');
    const rhs = argDef.desc || '';
    return [lhs, rhs, argDef];
  });

  const firstColWidth = _.max(
    _.map(usageTableRows, row => stripAnsi(row[0]).length)) + 1;

  const body = _.map(usageTableRows, (row) => {
    const rhsLines = row[1].split(/\n/mg);
    const firstRhsLine = rhsLines[0];
    rhsLines.splice(0, 1);

    const lhsSpacer = new Array((firstColWidth - stripAnsi(row[0]).length) + 1).join(' ');
    const paddedLhs = `${lhsSpacer}${row[0]}`;
    const firstLine = `${paddedLhs}: ${firstRhsLine}`;

    const skipLeft = new Array(firstColWidth + 1).join(' ');
    const paddedRhs = rhsLines.length ? _.map(rhsLines, line => `${skipLeft}${line}`).join('\n') : '';

    const argDef = row[2];
    let curVal = _.find(argDef.flags, flag => (flag in args ? args[flag] : null));
    if (!curVal) curVal = argDef.defVal || argDef.default || '';
    if (curVal) {
      curVal = `${skipLeft}  ${col.dim('Current:')} "${col.primary(curVal)}"`;
    }
    return _.filter([
      firstLine,
      paddedRhs,
      curVal,
    ]).join('\n');
  }).join('\n\n');

  return `\
${header}
${body}
`;
}
122471
function _forEach (array, callback) {
  // figure out what number of arguments the callback function expects
  const args = maxArgumentCount(callback)

  const recurse = function (value, index) {
    if (Array.isArray(value)) {
      forEachArray(value, function (child, i) {
        // we create a copy of the index array and append the new index value
        recurse(child, index.concat(i))
      })
    } else {
      // invoke the callback function with the right number of arguments
      if (args === 1) {
        callback(value)
      } else if (args === 2) {
        callback(value, index)
      } else { // 3 or -1
        callback(value, index, array)
      }
    }
  }
  recurse(array, [])
}
734061
function _preCommand(commands) {
  commander.on('--help', function () {

    var hasExample = _.map(_.values(commands), 'examples')
      .filter(function (elem) {
        return elem !== undefined;
      });
    if (hasExample.length > 0) {
      hasExample = hasExample.reduce(function (a, b) {
        return a.concat(b);
      });
    }
    hasExample = hasExample.length > 0;

    if (hasExample) {

      console.log('  Examples:\n');

      Object.keys(commands).forEach(function (command) {
        if (!_.isEmpty(commands[command].examples)) {
          console.log('    %s:', command);
          commands[command].examples.forEach(function (example) {
            console.log('      %s', example);
          });
        }
      });
    }
  });
}
960811
function showCommandsOnCmdEditor (config) {

	console.log(colors.bold('\nAvailable Commands for ' + config.deviceName + ':\n'));

	// Iterate the each commands
	var commands = config.commands || {};
	if (Object.keys(commands).length == 0) {
		console.log ('\nThere is no command.');
	} else {
		for (var name in commands) {
			var desc = commands[name].description || '';
			console.log(colors.bold('\n' + name + '') + '\n  ' + desc + '\n');

			// Iterate the each arguments
			var args = commands[name].args || {};
			if (Object.keys(args).length == 0) {
				console.log ('\tThe arguments of this command are not defined');
			} else {
				for (var arg_name in args) {
					var arg_spec = args[arg_name] || '';
					console.log('\t* ' + arg_name + ' - ' + arg_spec);
				}
			}

		}
	}

	console.log('\n');

	// Done
	return new Promise(function (resolve, reject) {
		resolve();
	});

}