From 151701e85f0beb1a7c896eb82c0d1f55ee380567 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 13 Apr 2021 15:07:21 -0400 Subject: progress: hide progress bar when --quiet We want progress bars in the default output mode, but not when the user specifies --quiet. Add a setting to the Progress bar class so it takes care of not displaying anything itself rather than having to update every subcommand to conditionally setup & call the object. Change-Id: I1134993bffc5437bc22e26be11a512125f10597f Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/303225 Reviewed-by: Raman Tenneti Tested-by: Mike Frysinger --- progress.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'progress.py') diff --git a/progress.py b/progress.py index de46f538..43c7ad21 100644 --- a/progress.py +++ b/progress.py @@ -42,7 +42,8 @@ def duration_str(total): class Progress(object): - def __init__(self, title, total=0, units='', print_newline=False, delay=True): + def __init__(self, title, total=0, units='', print_newline=False, delay=True, + quiet=False): self._title = title self._total = total self._done = 0 @@ -54,6 +55,13 @@ class Progress(object): self._show_jobs = False self._active = 0 + # When quiet, never show any output. It's a bit hacky, but reusing the + # existing logic that delays initial output keeps the rest of the class + # clean. Basically we set the start time to years in the future. + if quiet: + self._show = False + self._start += 2**32 + def start(self, name): self._active += 1 if not self._show_jobs: -- cgit v1.2.3-54-g00ecf