
from igen.include import *
from igen.igen import *
from igen.util import *

def main():
	from optparse import OptionParser, OptionGroup

	parser = OptionParser(
		prog = "igen",
		usage = "usage: %prog [options] [clang-args*]"
	)
	parser.disable_interspersed_args()
	(opts, clang_args) = parser.parse_args()

	if len(clang_args) == 0:
		parser.error("missing clang-args")

	paths = []
	for a in clang_args:
		if not a.startswith('-'):
			paths.append(a)
		else:
			break

	cindex.Config.set_library_file("libclang.so")
	#cindex.Config.set_library_file("/usr/lib/llvm-3.5/lib/libclang.so.1")
	#print("Config.library_file: %s" % cindex.Config.library_file)

	index = cindex.Index.create()

	tu = index.parse(None, clang_args)
	if not tu:
		parser.error("unable to load input")

	print("collecting")
	groups = {}
	for p in paths:
		groups[p] = Group(tu.cursor, p)
		x = Group(tu.cursor, p)

	print("groups:")
	for g in groups.values():
		print("  %s:" % g.path)
		for f in g.funcs:
			print("    %s in %s" % (f.signature_fqn(), f.contextual_parent or "<root>"))

if __name__ == "__main__":
	main()


import sys
import argparse

from igen.include import *
from igen import igen
from igen.util import *

def main():
	parser = argparse.ArgumentParser(
		prog = "igen",
		usage = "igen [options] path gen_path -- clang-args",
	)

	parser.add_argument("path", type = str, help = "path to parse")
	parser.add_argument("gen_path", type = str, help = "path to generate")

	if "--" not in sys.argv:
		parser.error("missing clang-args")

	arg_sep_index = sys.argv.index("--")
	opts = parser.parse_args(sys.argv[1:arg_sep_index])

	clang_args = sys.argv[arg_sep_index + 2:]
	if len(clang_args) == 0:
		parser.error("missing clang-args")

	cindex.Config.set_library_file("libclang.so")
	igen.generate(opts.path, opts.gen_path, clang_args, pre_filter = igen.make_pre_filter_path(opts.path))

if __name__ == "__main__":
	main()

use argparse instead of optparse; take single path and output; simplified.