import subprocess
import sys
import Alfred
 
handler = Alfred.Handler(args=sys.argv)
 
raw_query = handler.query
 
if " " in raw_query:
	query = raw_query.split(" ")
	lib_name = query[0]
	lib_version = query[1]
else:
	lib_name = raw_query
	lib_version = None
 
if lib_version is not None:
	sprocess = subprocess.Popen(["haxelib", "set", lib_name, lib_version], stdout=subprocess.PIPE)
 
	output = sprocess.stdout.read()
 
	print "%s: %s" % (lib_name, output)
else:
	print "%s: Please select a version." % lib_name