// Generated by IcedCoffeeScript 1.7.1-f
(function() {
  var Result, getopt,
    __slice = [].slice,
    __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

  Result = (function() {
    function Result() {
      this.args = [];
      this.opts = {};
    }

    Result.prototype.get = function() {
      var name, names, val, _i, _len;
      names = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
      if (names.length === 0) {
        return this.args;
      } else {
        for (_i = 0, _len = names.length; _i < _len; _i++) {
          name = names[_i];
          if ((val = this.opts[name]) != null) {
            return val;
          }
        }
        return null;
      }
    };

    return Result;

  })();

  module.exports = getopt = function(argv, _arg) {
    var arg, ch, flags, i, name, out, v, _i, _len, _ref, _ref1, _ref2;
    flags = _arg.flags;
    out = new Result;
    i = 0;
    while (i < argv.length) {
      arg = argv[i];
      if (arg === '--') {
        out.args = argv.slice(i + 1);
        break;
      } else if (arg[0] !== '-') {
        out.args = argv.slice(i);
        break;
      } else if (arg.slice(0, 2) === '--') {
        if (_ref = (name = arg.slice(2)), __indexOf.call(flags, _ref) >= 0) {
          out.opts[name] = true;
          i++;
        } else if (name.indexOf("=") > 1) {
          v = name.split(/\=/);
          out.opts[v[0]] = v.slice(1).join("=");
          i += 1;
        } else {
          out.opts[name] = argv[i + 1];
          i += 2;
        }
      } else if (_ref1 = arg[1], __indexOf.call(flags, _ref1) >= 0) {
        _ref2 = arg.slice(1);
        for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
          ch = _ref2[_i];
          out.opts[ch] = true;
        }
        i++;
      } else if (arg.length === 2) {
        out.opts[arg.slice(1)] = argv[i + 1];
        i += 2;
      } else {
        out.opts[arg[1]] = arg.slice(2);
        i++;
      }
    }
    return out;
  };

}).call(this);
