import sys
import subprocess
import Alfred
 
handler = Alfred.Handler(args=sys.argv)
 
raw_result = subprocess.Popen(["haxelib", "search", handler.query], stdout=subprocess.PIPE).stdout.read()
 
haxelib_result = raw_result.split("\n")
 
# remove blank line
haxelib_result = haxelib_result[0:-1]
 
number_of_libs = haxelib_result[-1].split(" ")[0]
 
# remove number of libraries
haxelib_result = haxelib_result[0:-1]
 
for result in haxelib_result:
	item = Alfred.Item(title=result, uid=result, arg=result)
	handler.add_item(item)
 
handler.push()