From 3f802a17d18f790a997fb5fc7ababcc6bbdaa2b1 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 15 Mar 2009 14:52:45 -0400 Subject: The cmdline code now returns a status code. --- coverage/cmdline.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'coverage/cmdline.py') diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 0787f19e..2d4977c7 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -45,6 +45,7 @@ Coverage data is saved in the file .coverage by default. Set the COVERAGE_FILE environment variable to save it somewhere else. """.strip() + class CoverageScript: def __init__(self): import coverage @@ -56,11 +57,11 @@ class CoverageScript: print error print print USAGE % self.covpkg.__dict__ - sys.exit(1) def command_line(self, argv, help_fn=None): # Collect the command-line options. help_fn = help_fn or self.help + OK, ERR = 0, 1 settings = {} optmap = { '-a': 'annotate', @@ -90,6 +91,7 @@ class CoverageScript: if settings.get('help'): help_fn() + return OK # Check for conflicts and problems in the options. for i in ['erase', 'execute']: @@ -97,6 +99,7 @@ class CoverageScript: if settings.get(i) and settings.get(j): help_fn("You can't specify the '%s' and '%s' " "options at the same time." % (i, j)) + return ERR args_needed = (settings.get('execute') or settings.get('annotate') @@ -106,8 +109,10 @@ class CoverageScript: or args_needed) if not action: help_fn("You must specify at least one of -e, -x, -c, -r, or -a.") + return ERR if not args_needed and args: help_fn("Unexpected arguments: %s" % " ".join(args)) + return ERR # Do something. self.coverage.parallel_mode = settings.get('parallel-mode') @@ -119,6 +124,7 @@ class CoverageScript: if settings.get('execute'): if not args: help_fn("Nothing to do.") + return ERR # Create the runtime environment the script on the cmdline expects. sys.argv = args sys.path[0] = os.path.dirname(sys.argv[0]) @@ -144,9 +150,10 @@ class CoverageScript: if settings.get('annotate'): reporter = AnnotateReporter(self.coverage, ignore_errors) reporter.report(args, directory, omit_prefixes=omit) - + + return OK # Main entrypoint. This is installed as the script entrypoint, so don't # refactor it away... def main(): - CoverageScript().command_line(sys.argv[1:]) + return CoverageScript().command_line(sys.argv[1:]) -- cgit v1.2.1