From f9aacd4087b02948da9a7878da48ea186ab99d5a Mon Sep 17 00:00:00 2001 From: Jason Chang Date: Thu, 3 Aug 2023 14:38:00 -0700 Subject: Raise repo exit errors in place of sys.exit Bug: b/293344017 Change-Id: I92d81c78eba8ff31b5252415f4c9a515a6c76411 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/381774 Tested-by: Jason Chang Reviewed-by: Joanna Wang Commit-Queue: Jason Chang --- command.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'command.py') diff --git a/command.py b/command.py index 939a4630..d2129381 100644 --- a/command.py +++ b/command.py @@ -16,11 +16,11 @@ import multiprocessing import os import optparse import re -import sys from event_log import EventLog from error import NoSuchProjectError from error import InvalidProjectGroupsError +from error import RepoExitError import progress @@ -42,6 +42,10 @@ WORKER_BATCH_SIZE = 32 DEFAULT_LOCAL_JOBS = min(os.cpu_count(), 8) +class UsageError(RepoExitError): + """Exception thrown with invalid command usage.""" + + class Command(object): """Base class for any command line action in repo.""" @@ -215,7 +219,7 @@ class Command(object): def Usage(self): """Display usage and terminate.""" self.OptionParser.print_usage() - sys.exit(1) + raise UsageError() def CommonValidateOptions(self, opt, args): """Validate common options.""" -- cgit v1.2.3-54-g00ecf