2017-11-07 03:01:24 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# ./dev --help
|
2016-12-24 18:46:07 +00:00
|
|
|
|
2017-11-07 03:01:24 +00:00
|
|
|
import argparse
|
2016-12-24 18:46:07 +00:00
|
|
|
import os
|
2017-11-07 03:01:24 +00:00
|
|
|
from subprocess import run
|
2016-12-24 18:46:07 +00:00
|
|
|
import sys
|
|
|
|
|
2017-11-07 03:01:24 +00:00
|
|
|
parser = argparse.ArgumentParser(prog='./dev')
|
|
|
|
subparsers = parser.add_subparsers(metavar='<command>', title='commands')
|
|
|
|
command = [
|
|
|
|
'docker', 'run', '-it', '--rm', '-v', os.getcwd() + ':/src:cached',
|
2019-04-08 21:24:51 +00:00
|
|
|
'-w=/src', 'rust:1.31.0'
|
2017-11-07 03:01:24 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
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()
|