diff --git a/README.md b/README.md index d49c95a..5a6ea31 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ this by cloning the source repository to somewhere on your machine and running `pip install`: ```shell -git clone https://github.com/olin/focstest.git +git clone --branch=release https://github.com/olin/focstest.git # clone a stable version pip install focstest/ ``` @@ -119,15 +119,14 @@ refresh `focstest`'s copy, use the `--update-cache` flag: focstest homework2.ml --update-cache ``` - `focstest` uses a standard python-powered command-line interface. You can always ask it for help with `--help` or `-h`. -``` +```shell $ focstest --help -usage: focstest [-h] [-u URL] [-v] [--log-level {debug,info,warning}] [-uc] - [-U [N [N ...]] | -S [N [N ...]]] - ocaml-file +usage: focstest [-h] [--version] [--url URL] [-v] [-uc] [-u [N [N ...]] | -s + [N [N ...]]] + ocaml-file Run ocaml "doctests". @@ -136,15 +135,17 @@ positional arguments: optional arguments: -h, --help show this help message and exit - -u URL, --url URL a url to scrape tests from + --version show program's version number and exit + --url URL a url to scrape tests from (usually automagically + guessed from ocaml-file) -v, --verbose increase test output verbosity - --log-level {debug,info,warning} - the program log level -uc, --update-cache update cached files - -U [N [N ...]], --use-suites [N [N ...]] + -u [N [N ...]], --use-suites [N [N ...]] test suites to use exclusively, indexed from 1 - -S [N [N ...]], --skip-suites [N [N ...]] + -s [N [N ...]], --skip-suites [N [N ...]] test suites to skip, indexed from 1 + +Submit bugs to . ``` For most homeworks, the workflow that I've used is going question by question @@ -181,3 +182,10 @@ Run `pipenv install --dev` to install all of the dev packages. Run tests with `python -m unittest discover`. Want to use it while you hack on it? Install it with `pip install -e`. + +You can set `focstest`'s logging level with the `LOG_LEVEL` environment variable. +The possible values are all of python's usual logging levels, set it to `DEBUG` +for more output. +```shell +$ LOG_LEVEL=DEBUG focstest homework3.ml +``` diff --git a/focstest.py b/focstest.py index ec5e150..eaed45d 100755 --- a/focstest.py +++ b/focstest.py @@ -196,27 +196,32 @@ def main(): epilog='Submit bugs to .') parser.add_argument('--version', action='version', version=__version__) input_types = parser.add_mutually_exclusive_group(required=False) - input_types.add_argument('-u', '--url', type=str, - help='a url to scrape tests from (usually automagically guessed based on ocaml-file)') - # input_types.add_argument('-f', '--file', type=str, - # help='a file to load tests from') + input_types.add_argument('--url', type=str, + help='a url to scrape tests from (usually automagically guessed from ocaml-file)') parser.add_argument('ocaml-file', type=str, help='the ocaml file to test against') parser.add_argument('-v', '--verbose', action='store_true', help='increase test output verbosity') - parser.add_argument('--log-level', choices=['debug', 'info', 'warning'], - help='the program log level') parser.add_argument('-uc', '--update-cache', action='store_true', help='update cached files') test_selection = parser.add_mutually_exclusive_group(required=False) - test_selection.add_argument('-U', '--use-suites', metavar='N', type=int, nargs='*', + test_selection.add_argument('-u', '--use-suites', metavar='N', type=int, nargs='*', help='test suites to use exclusively, indexed from 1') - test_selection.add_argument('-S', '--skip-suites', metavar='N', type=int, nargs='*', + test_selection.add_argument('-s', '--skip-suites', metavar='N', type=int, nargs='*', help='test suites to skip, indexed from 1') args = parser.parse_args() - if args.log_level: - numeric_level = getattr(logging, args.log_level.upper(), None) - logger.setLevel(numeric_level) + + # check environment var for logging level + log_level = os.getenv('LOG_LEVEL') + if log_level is not None: + log_level = log_level.upper() + try: + numeric_level = getattr(logging, os.getenv('LOG_LEVEL')) + except AttributeError as e: + logging.warning("Found 'LOG_LEVEL' env var, but was unable to parse: {}".format(e)) + else: + logger.setLevel(numeric_level) + logger.debug('Set logging level to {!r} ({}) from env var'.format(log_level, numeric_level)) URL = args.url FILE = getattr(args, 'ocaml-file') @@ -224,7 +229,7 @@ def main(): if not args.url: url_guess = infer_url(FILE) if not url_guess: # break if filename can't be matched - logger.critical('Could not infer url from filename {!r}. Try passing a url manually with the `-u`/`--url` flag.'.format(FILE)) + logger.critical('Could not infer url from filename {!r}. Try passing a url manually with the `--url` flag.'.format(FILE)) sys.exit(1) else: URL = url_guess