summaryrefslogtreecommitdiffstats
path: root/command.py
diff options
context:
space:
mode:
authorJason Chang <jasonnc@google.com>2023-08-03 14:38:00 -0700
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-08-07 23:56:07 +0000
commitf9aacd4087b02948da9a7878da48ea186ab99d5a (patch)
treeb683190635cd6fcb7cf817837ad0c4259b53078f /command.py
parentb8a7b4a629c3435d77a3266a4e6dce51dc342bd9 (diff)
downloadgit-repo-f9aacd4087b02948da9a7878da48ea186ab99d5a.tar.gz
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 <jasonnc@google.com> Reviewed-by: Joanna Wang <jojwang@google.com> Commit-Queue: Jason Chang <jasonnc@google.com>
Diffstat (limited to 'command.py')
-rw-r--r--command.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/command.py b/command.py
index 939a4630..d2129381 100644
--- a/command.py
+++ b/command.py
@@ -16,11 +16,11 @@ import multiprocessing
16import os 16import os
17import optparse 17import optparse
18import re 18import re
19import sys
20 19
21from event_log import EventLog 20from event_log import EventLog
22from error import NoSuchProjectError 21from error import NoSuchProjectError
23from error import InvalidProjectGroupsError 22from error import InvalidProjectGroupsError
23from error import RepoExitError
24import progress 24import progress
25 25
26 26
@@ -42,6 +42,10 @@ WORKER_BATCH_SIZE = 32
42DEFAULT_LOCAL_JOBS = min(os.cpu_count(), 8) 42DEFAULT_LOCAL_JOBS = min(os.cpu_count(), 8)
43 43
44 44
45class UsageError(RepoExitError):
46 """Exception thrown with invalid command usage."""
47
48
45class Command(object): 49class Command(object):
46 """Base class for any command line action in repo.""" 50 """Base class for any command line action in repo."""
47 51
@@ -215,7 +219,7 @@ class Command(object):
215 def Usage(self): 219 def Usage(self):
216 """Display usage and terminate.""" 220 """Display usage and terminate."""
217 self.OptionParser.print_usage() 221 self.OptionParser.print_usage()
218 sys.exit(1) 222 raise UsageError()
219 223
220 def CommonValidateOptions(self, opt, args): 224 def CommonValidateOptions(self, opt, args):
221 """Validate common options.""" 225 """Validate common options."""