From 1e88007bf9f6c09cbd0bc1261c0e5b805b21f1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ely=C3=A9zer=20Rezende?= Date: Sat, 11 Jun 2016 21:14:42 -0300 Subject: [PATCH] Use Click library instead of argparse Close #79 --- bin/testimony | 3 --- setup.py | 6 ++++- testimony/__main__.py | 52 ------------------------------------------- testimony/cli.py | 23 +++++++++++++++++++ 4 files changed, 28 insertions(+), 56 deletions(-) delete mode 100755 bin/testimony delete mode 100644 testimony/__main__.py create mode 100644 testimony/cli.py diff --git a/bin/testimony b/bin/testimony deleted file mode 100755 index 21e3e3f..0000000 --- a/bin/testimony +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -python -m testimony "$@" diff --git a/setup.py b/setup.py index 5c3250f..3c7ff86 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,11 @@ author='Suresh Thirugn', author_email='sthirugn@redhat.com', packages=['testimony'], - scripts=['bin/testimony'], + install_requires=['Click'], + entry_points=''' + [console_scripts] + testimony=testimony.cli:testimony + ''', description='Testimony inspects and reports on the python test cases.', long_description=long_description, license=license, diff --git a/testimony/__main__.py b/testimony/__main__.py deleted file mode 100644 index 709ce65..0000000 --- a/testimony/__main__.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- encoding: utf-8 -*- -"""Main module for testimony""" - -import argparse -import os.path - -from testimony import main -from testimony.constants import REPORT_TAGS - - -def file_or_dir_arg(arg): - """Checks if a path argument is a file or a directory.""" - if os.path.isdir(arg) or os.path.isfile(arg): - return arg - else: - msg = '%s is not a file or a directory' % arg - raise argparse.ArgumentTypeError(msg) - - -def parse_args(): - """Argument parser for testimony""" - parser = argparse.ArgumentParser( - description='Inspects and report on the Python test cases.', - prog='testimony') - parser.add_argument( - 'report', type=str, choices=REPORT_TAGS, - metavar='REPORT', - help='report type, possible values: %s' % ', '.join(REPORT_TAGS)) - parser.add_argument( - 'paths', metavar='PATH', type=file_or_dir_arg, nargs='+', - help='a list of paths to look for tests cases') - parser.add_argument( - '-j', '--json', action='store_true', help='JSON output') - parser.add_argument( - '-n', '--nocolor', action='store_true', help='Do not use color option') - parser.add_argument( - '-t', - '--tags', - nargs='*', - help='space separated tags to search. Note: Always run this ' - 'only in the root of the project where test cases are stored' - ) - args = parser.parse_args() - return args - - -def run(args): - """Run testimony with given args""" - main(args.report, args.paths, args.json, args.nocolor, args.tags) - -if __name__ == "__main__": - run(parse_args()) diff --git a/testimony/cli.py b/testimony/cli.py new file mode 100644 index 0000000..19de7cf --- /dev/null +++ b/testimony/cli.py @@ -0,0 +1,23 @@ +# coding=utf-8 +"""Testimony CLI utilities.""" +import click + +from testimony import main +from testimony.constants import REPORT_TAGS + + +@click.command() +@click.option('-j', '--json', help='JSON output', is_flag=True) +@click.option('-n', '--nocolor', default=False, help='Color output', + is_flag=True) +@click.option( + '-t', '--tag', multiple=True, + help='specify a tag to search. This option can be specified multiple ' + 'times. Note: Always run this only in the root of the project where ' + 'test cases are stored' +) +@click.argument('report', type=click.Choice(REPORT_TAGS)) +@click.argument('path', nargs=-1, type=click.Path(exists=True)) +def testimony(json, nocolor, tag, report, path): + """Inspects and report on the Python test cases.""" + main(report, path, json, nocolor, tag)