       if elem.index >= gte
         ++elem.index)
     return list
+
+  _getOption: (opt, listName) =>
+    option = @_options.filter((mem) ->
+      if opt.arg is mem.name and listName is mem.list
+        return mem)
+    return `option.length === 0 ? undefined : option[0]`
+
+  _setOptionArg: (opt, listName) =>
+    option = @_getOption(opt, listName)
+    option.arg = opt.optarg
+    if option.child isnt null
+      @_options[option.child.index].arg = opt.optarg
+    if option.parent isnt null
+      @_options[option.parent.index].arg = opt.optarg
+    return undefined
 
 # XXX transforms `-hxv' into `-h -x -v'
   _splitCombinedShorts: () =>


  _takesArg: (opt, listName) =>
    @_catchInvalidOpt(opt, listName)
    if listName is 'short'
      type = @_short[opt.arg].type
      if type isnt 'flag'
        return true
      else
        return false
    else
      type = @_long[opt.arg].type
      if type isnt 'flag'
        return true
      else
        return false

  _log: (y) ->
    console.log(util.inspect(y, { colors: true, depth: null }))

            index: ind }))

  _runCallbacks: () =>
    @_cooked.forEach((opt) =>
      arg = opt.cb.apply(@, [opt.arg])
      @_eaten[opt.name] = arg
      if opt.child isnt null
        @_eaten[opt.child.name] = arg
      if opt.parent isnt null
        @_eaten[opt.parent.name] = arg)

  _clean: () =>
    Object.keys(@).forEach((key) =>
      if /^_/.test(key)
        switch key
          when '_runCallbacks'
            null
          when '_raw'
            null
          when '_cooked'
            null
          when '_eaten'
            null
          when '_help'
            null
          else
            delete @[key])

  parse: () =>
    @_makeHelp()
    @_gather()
    @_resolveOpts()
    @_clean()
    @_runCallbacks()
    return @_eaten

module.exports = Bebopt
