forked from slashmili/alchemist.vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalchemist_client
executable file
·77 lines (65 loc) · 2.69 KB
/
alchemist_client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/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
Options:
-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 = ""
try:
opts, args = getopt.getopt(argv,"hc:t:d:a:s:",["type=","command-type=", "directory=", "alchemist-server=", "colors=", "source="])
except getopt.GetoptError:
print(alchemist_help())
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print(alchemist_help())
sys.exit()
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")
print(alchemist_help())
sys.exit(2)
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__":
main(sys.argv[1:])