diff --git a/README.md b/README.md index dc0a1e3..5967685 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,8 @@ fn main() { ``` ### Development -If you don't want to install Rust itself, you can install [Docker], and run -`$ ./dev`. This should bring up a temporary container from which you can run -[cargo] commands. +If you don't want to install Rust itself, you can run `$ ./dev` for a +development CLI if you have [Docker] installed. ### License [MIT](https://github.com/dguo/strsim-rs/blob/master/LICENSE) @@ -91,5 +90,3 @@ If you don't want to install Rust itself, you can install [Docker], and run [Hamming]:http://en.wikipedia.org/wiki/Hamming_distance [Optimal string alignment]:https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance#Optimal_string_alignment_distance [Docker]:https://docs.docker.com/engine/installation/ -[cargo]:https://github.com/rust-lang/cargo - diff --git a/dev b/dev index 6588873..4c85a49 100755 --- a/dev +++ b/dev @@ -1,13 +1,41 @@ -#!/usr/bin/env python - -from __future__ import print_function +#!/usr/bin/env python3 +# ./dev --help +import argparse import os -from subprocess import call +from subprocess import run import sys -try: - call(['docker', 'run', '-it', '--rm', '-v', os.getcwd() + ':/src:cached', - '-w=/src', 'rust:1.20.0']) -except OSError: - print('Please install Docker.', file=sys.stderr) +parser = argparse.ArgumentParser(prog='./dev') +subparsers = parser.add_subparsers(metavar='', title='commands') +command = [ + 'docker', 'run', '-it', '--rm', '-v', os.getcwd() + ':/src:cached', + '-w=/src', 'rust:1.21.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()