Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ optional arguments:
-h, --help show this help message and exit
-v, --verbose Verbose mode.
--version Display version information.
--json Print detect-secrets-hook output as JSON
--baseline FILENAME Explicitly ignore secrets through a baseline generated
by `detect-secrets scan`

Expand Down
7 changes: 5 additions & 2 deletions detect_secrets/core/usage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def add_default_options(self) -> 'ParserBuilder':
'using the max cores on the current host.'
),
)

return self

def add_console_use_arguments(self) -> 'ParserBuilder':
Expand Down Expand Up @@ -92,7 +91,11 @@ def add_pre_commit_arguments(self) -> 'ParserBuilder':
nargs='*',
help='Filenames to check.',
)

self._parser.add_argument(
'--json',
action='store_true',
help='Print detect-secrets-hook output as JSON',
)
self.add_baseline_options(
help=(
'Explicitly ignore secrets through a baseline generated by `detect-secrets scan`'
Expand Down
5 changes: 4 additions & 1 deletion detect_secrets/pre_commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def main(argv: Optional[List[str]] = None) -> int:
new_secrets = secrets - args.baseline

if new_secrets:
pretty_print_diagnostics(new_secrets)
if args.json:
print(json.dumps(baseline.format_for_output(new_secrets), indent=2))
else:
pretty_print_diagnostics(new_secrets)
return 1

if not args.baseline:
Expand Down