local flags = {}
-- from http://www.luafaq.org/#T2.2
--- Extract flags from an arguments list.
-- Given string arguments, extract flag arguments into a flags set.
-- For example, given "foo", "--tux=beep", "--bla", "bar", "--baz",
-- it would return the following:
-- {["bla"] = true, ["tux"] = "beep", ["baz"] = true}, "foo", "bar".
function flags.parse(args)
	local flags = {}
	local i
	for i = #args, 1, -1 do
		local flag = args[i]:match("^%-%-(.*)")
		if flag then
			local var,val = flag:match("([a-z_%-]*)=(.*)")
			if val then
				flags[var] = val
			else
				flags[flag] = true
			end
			table.remove(args, i)
		end
	end
	return flags, unpack(args)
end

return flags
