Skip to content

Commit 1c59d19

Browse files
committed
refactor: remove verbose arg from GGShieldUI methods
1 parent 6c3560b commit 1c59d19

File tree

10 files changed

+26
-62
lines changed

10 files changed

+26
-62
lines changed

ggshield/cmd/secret/scan/archive.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def archive_cmd(
4444

4545
ctx_obj = ContextObj.get(ctx)
4646
config = ctx_obj.config
47-
verbose = ui.is_verbose()
4847
files, binary_paths = create_files_from_paths(
4948
paths=[temp_path],
5049
exclusion_regexes=ctx_obj.exclusion_regexes,
@@ -53,7 +52,7 @@ def archive_cmd(
5352
print_file_list(files, binary_paths)
5453
ui.display_heading("Starting scan")
5554

56-
with ui.create_scanner_ui(len(files), verbose=verbose) as scanner_ui:
55+
with ui.create_scanner_ui(len(files)) as scanner_ui:
5756
scan_context = ScanContext(
5857
scan_mode=ScanMode.ARCHIVE,
5958
command_path=ctx.command_path,

ggshield/cmd/secret/scan/docset.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@ def generate_files_from_docsets(file: TextIO) -> Iterator[Scannable]:
2525

2626

2727
def create_scans_from_docset_files(
28-
scanner: SecretScanner,
29-
input_files: Iterable[TextIO],
30-
progress: GGShieldProgress,
31-
verbose: bool = False,
28+
scanner: SecretScanner, input_files: Iterable[TextIO], progress: GGShieldProgress
3229
) -> List[SecretScanCollection]:
3330
scans: List[SecretScanCollection] = []
3431

3532
for input_file in input_files:
3633
ui.display_verbose(f"- {click.format_filename(input_file.name)}")
3734

3835
files = generate_files_from_docsets(input_file)
39-
with ui.create_message_only_scanner_ui(verbose=verbose) as scanner_ui:
36+
with ui.create_message_only_scanner_ui() as scanner_ui:
4037
results = scanner.scan(files, scanner_ui=scanner_ui)
4138
scans.append(
4239
SecretScanCollection(id=input_file.name, type="docset", results=results)
@@ -81,10 +78,7 @@ def docset_cmd(
8178
ignored_detectors=config.user_config.secret.ignored_detectors,
8279
)
8380
scans = create_scans_from_docset_files(
84-
scanner=scanner,
85-
input_files=files,
86-
progress=progress,
87-
verbose=ui.is_verbose(),
81+
scanner=scanner, input_files=files, progress=progress
8882
)
8983

9084
return output_handler.process_scan(

ggshield/cmd/secret/scan/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def path_cmd(
6969
ui.display_heading("Starting scan")
7070
target = paths[0] if len(paths) == 1 else Path.cwd()
7171
target_path = target if target.is_dir() else target.parent
72-
with ui.create_scanner_ui(len(files), verbose=ui.is_verbose()) as scanner_ui:
72+
with ui.create_scanner_ui(len(files)) as scanner_ui:
7373
scan_context = ScanContext(
7474
scan_mode=ScanMode.PATH,
7575
command_path=ctx.command_path,

ggshield/cmd/secret/scan/precommit.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,13 @@ def precommit_cmd(
6060
"""
6161
ctx_obj = ContextObj.get(ctx)
6262
config = ctx_obj.config
63-
verbose = ui.is_verbose()
6463

6564
if check_user_requested_skip():
6665
return 0
6766

6867
output_handler = SecretTextOutputHandler(
6968
show_secrets=config.user_config.secret.show_secrets,
70-
verbose=verbose,
69+
verbose=ui.is_verbose(),
7170
client=ctx_obj.client,
7271
output=None,
7372
ignore_known_secrets=config.user_config.secret.ignore_known_secrets,
@@ -97,7 +96,7 @@ def precommit_cmd(
9796
ignored_matches=config.user_config.secret.ignored_matches,
9897
ignored_detectors=config.user_config.secret.ignored_detectors,
9998
)
100-
with ui.create_scanner_ui(len(commit.urls), verbose=verbose) as scanner_ui:
99+
with ui.create_scanner_ui(len(commit.urls)) as scanner_ui:
101100
results = scanner.scan(commit.get_files(), scanner_ui)
102101

103102
return_code = output_handler.process_scan(

ggshield/cmd/secret/scan/pypi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def pypi_cmd(
9898
ctx_obj = ContextObj.get(ctx)
9999
config = ctx_obj.config
100100
output_handler = create_output_handler(ctx)
101-
verbose = ui.is_verbose()
102101

103102
with tempfile.TemporaryDirectory(suffix="ggshield") as temp_dir:
104103
temp_path = Path(temp_dir)
@@ -112,7 +111,7 @@ def pypi_cmd(
112111
print_file_list(files, binary_paths)
113112
ui.display_heading("Starting scan")
114113

115-
with ui.create_scanner_ui(len(files), verbose=verbose) as scanner_ui:
114+
with ui.create_scanner_ui(len(files)) as scanner_ui:
116115
scan_context = ScanContext(
117116
scan_mode=ScanMode.PYPI,
118117
command_path=ctx.command_path,

ggshield/core/ui/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def create_progress(total: int) -> GGShieldProgress:
8181
return _ui.create_progress(total)
8282

8383

84-
def create_scanner_ui(total: int, verbose: bool = False) -> ScannerUI:
85-
return _ui.create_scanner_ui(total, verbose=verbose)
84+
def create_scanner_ui(total: int) -> ScannerUI:
85+
return _ui.create_scanner_ui(total)
8686

8787

88-
def create_message_only_scanner_ui(verbose: bool = False) -> ScannerUI:
89-
return _ui.create_message_only_scanner_ui(verbose=verbose)
88+
def create_message_only_scanner_ui() -> ScannerUI:
89+
return _ui.create_message_only_scanner_ui()
9090

9191

9292
def _reset_ui():

ggshield/core/ui/ggshield_ui.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,15 @@ def __init__(self):
5757
self.level = Level.INFO
5858

5959
@abstractmethod
60-
def create_scanner_ui(
61-
self,
62-
total: int,
63-
verbose: bool = False,
64-
) -> ScannerUI:
60+
def create_scanner_ui(self, total: int) -> ScannerUI:
6561
"""
6662
Creates a ScannerUI instance. This is used to show progress on scanning
6763
Scannables.
6864
"""
6965
...
7066

7167
@abstractmethod
72-
def create_message_only_scanner_ui(
73-
self,
74-
verbose: bool = False,
75-
) -> ScannerUI:
68+
def create_message_only_scanner_ui(self) -> ScannerUI:
7669
"""
7770
Creates a ScannerUI instance without a progress bar. This is used when the scan
7871
itself is part of a larger scan. For example when scanning a commit range, each

ggshield/core/ui/plain_text/plain_text_ggshield_ui.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,10 @@ def log(self, record: logging.LogRecord) -> None:
5959
self.display_warning(f"Unsupported log level {level}")
6060
self.display_error(msg)
6161

62-
def create_scanner_ui(
63-
self,
64-
total: int,
65-
verbose: bool = False,
66-
) -> ScannerUI:
62+
def create_scanner_ui(self, total: int) -> ScannerUI:
6763
return PlainTextScannerUI()
6864

69-
def create_message_only_scanner_ui(
70-
self,
71-
verbose: bool = False,
72-
) -> ScannerUI:
65+
def create_message_only_scanner_ui(self) -> ScannerUI:
7366
return PlainTextScannerUI()
7467

7568
def create_progress(self, total: int) -> GGShieldProgress:

ggshield/core/ui/rich/rich_ggshield_ui.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,11 @@ def __init__(self):
6363
self.console = Console(file=sys.stderr)
6464
self._previous_timestamp = ""
6565

66-
def create_scanner_ui(
67-
self,
68-
total: int,
69-
verbose: bool = False,
70-
) -> ScannerUI:
71-
return RichProgressScannerUI(self, total, verbose)
72-
73-
def create_message_only_scanner_ui(
74-
self,
75-
verbose: bool = False,
76-
) -> ScannerUI:
77-
return RichMessageOnlyScannerUI(self, verbose)
66+
def create_scanner_ui(self, total: int) -> ScannerUI:
67+
return RichProgressScannerUI(self, total)
68+
69+
def create_message_only_scanner_ui(self) -> ScannerUI:
70+
return RichMessageOnlyScannerUI(self)
7871

7972
def create_progress(self, total: int) -> GGShieldProgress:
8073
return RichGGShieldProgress(self.console, total)

ggshield/core/ui/rich/rich_scanner_ui.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ class RichMessageOnlyScannerUI(ScannerUI):
1212
Basic UI, only supports showing messages when `on_*()` methods are called
1313
"""
1414

15-
def __init__(
16-
self,
17-
ui: GGShieldUI,
18-
verbose: bool = False,
19-
):
15+
def __init__(self, ui: GGShieldUI):
2016
self.ui = ui
21-
self.verbose = verbose
2217

2318
def __enter__(self) -> Self:
2419
return self
@@ -27,9 +22,8 @@ def __exit__(self, *args: Any) -> None:
2722
pass
2823

2924
def on_scanned(self, scannables: Sequence[Scannable]) -> None:
30-
if self.verbose:
31-
for scannable in scannables:
32-
self.ui.display_info(f"Scanned {scannable.path}")
25+
for scannable in scannables:
26+
self.ui.display_verbose(f"Scanned {scannable.path}")
3327

3428
def on_skipped(self, scannable: Scannable, reason: str) -> None:
3529
if reason:
@@ -42,8 +36,8 @@ class RichProgressScannerUI(RichMessageOnlyScannerUI):
4236
Show a progress bar in addition to messages when `on_*()` methods are called
4337
"""
4438

45-
def __init__(self, ui: GGShieldUI, total: int, verbose: bool = False):
46-
super().__init__(ui, verbose)
39+
def __init__(self, ui: GGShieldUI, total: int):
40+
super().__init__(ui)
4741
self.progress = ui.create_progress(total)
4842

4943
def __enter__(self) -> Self:

0 commit comments

Comments
 (0)