forked from Distributive-Network/PythonMonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
36 lines (30 loc) · 1.11 KB
/
cli.py
File metadata and controls
36 lines (30 loc) · 1.11 KB
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
import os, sys
import subprocess
import argparse
def execute(cmd: str, cwd: str):
popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
shell = True, text = True, cwd = cwd )
for stdout_line in iter(popen.stdout.readline, ""):
sys.stdout.write(stdout_line)
sys.stdout.flush()
popen.stdout.close()
return_code = popen.wait()
if return_code != 0:
sys.exit(return_code)
def commandType(value: str):
if value != "npm":
raise argparse.ArgumentTypeError("Value must be npm.")
return value
def main():
parser = argparse.ArgumentParser(description="A tool to enable running npm on the correct package.json location")
parser.add_argument("executable", nargs=1, help="Should be npm.", type=commandType)
parser.add_argument("args", nargs = argparse.REMAINDER)
args = parser.parse_args()
pythonmonkey_path= os.path.realpath(
os.path.join(
os.path.dirname(__file__),
'..',
'pythonmonkey'
)
)
execute(' '.join( args.executable + args.args ), pythonmonkey_path)