Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 78 lines (65 sloc) 2.69 KB
#!/usr/bin/env python
from __future__ import print_function
import os, sys, getopt
from alchemist import AlchemistClient
debug = False
read_stdin = vars(__builtins__).get('raw_input',input)
def alchemist_help():
return """Usage: alchemist_client -c <command> -t <command_type> -d <working_directory> -a <alchemist_script>
a client that talks to alchemist_server through network socket
-c, --command="" Command that is going to be sent to alchemist server if nothing is provided read a line from STDIN
-t, --command-type="" Command type, if it's not provided, extract it from command
-d, --directory= Directory that alchemist server should process code from
-a, --alchemist-server="" Path to alchemist server `run.exs`, if it's not provided load it from alchemist-server/run.exs
-s, --source="" Path to source code for Erlang and Elixir. It's used to find the path in DEFLX command
--colors=true Enable/Disable ansi
def main(argv):
cmd_type = ""
cmd = ""
cwd = ""
alchemist_script = ""
ansi = True
source = ""
opts, args = getopt.getopt(argv,"hc:t:d:a:s:",["type=","command-type=", "directory=", "alchemist-server=", "colors=", "source="])
except getopt.GetoptError:
for opt, arg in opts:
if opt == '-h':
elif opt in ("-c", "--command"):
cmd = arg
elif opt in ("-t", "--command-type"):
cmd_type = arg
elif opt in ("-d", "--directory"):
cwd = arg
elif opt in ("-a", "--alchemist-server"):
alchemist_script = arg
elif opt in ("-s", "--source"):
source = arg
elif opt in ("--colors"):
if arg == "false":
ansi = False
if os.path.exists(cwd.strip()) == False:
raise Exception("working directory [%s] doesn't exist" % cwd)
cwd = os.path.abspath(cwd)
if cmd == "":
cmd = read_stdin()
if alchemist_script == "":
alchemist_script = "%s/alchemist-server/run.exs" % where_am_i()
if cmd_type == "":
cmd_type = cmd.split(" ")[0]
if cmd == "" or cmd_type == "" or alchemist_script == "" or cwd == "":
print("Invalid command, alchemist_script or working directory")
a = AlchemistClient(debug=debug, cwd=cwd, ansi=ansi, alchemist_script=alchemist_script, source=source)
print(a.process_command(cmd), end="")
def where_am_i():
return os.path.dirname(os.path.realpath(__file__))
if __name__ == "__main__":