-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
dev
executable file
·41 lines (32 loc) · 1.1 KB
/
dev
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
#!/usr/bin/env python3
# ./dev --help
import argparse
import os
from subprocess import run
import sys
parser = argparse.ArgumentParser(prog='./dev')
subparsers = parser.add_subparsers(metavar='<command>', title='commands')
command = [
'docker', 'run', '-it', '--rm', '-v', os.getcwd() + ':/src:cached',
'-w=/src', 'rust:1.31.0'
]
def cargo(args, remaining):
sys.exit(run(command + ['cargo'] + remaining or []).returncode)
parser_cargo = subparsers.add_parser('cargo', help='run a cargo command')
parser_cargo.set_defaults(func=cargo)
def sh(args, remaining):
sys.exit(run(command + ['bash']).returncode)
parser_sh = subparsers.add_parser('sh', help='bring up a shell')
parser_sh.set_defaults(func=sh)
def test(args, remaining):
sys.exit(run(command + ['cargo', 'test']).returncode)
parser_test = subparsers.add_parser('test', help='run tests')
parser_test.set_defaults(func=test)
if len(sys.argv) > 1:
args, remaining = parser.parse_known_args()
try:
args.func(args, remaining)
except FileNotFoundError:
sys.exit('Please install Docker.')
else:
parser.print_help()