Skip to content

Commit 71ec8ea

Browse files
committed
fix(with_incident_details): # We add a default value None to the click option to fix the behavior of the option
If no default value is defined, the behavior of ggshield can be misleading and actually bugged. Indeed, each command or subcommand uses the decorator "add_secret_scan_common_options" to collect values of several command options. This lets the user place the option --with-incident-details at several level in the command line. If they do so, the command or subcommand that does not have the flag will set the value to False which can prevent the option from working correctly. For instance: `ggshield secret scan --with-incident-details path dummy.py` => The option is set to False in the end because the path subcommand does not have the option defined. `ggshield secret scan path --with-incident-details dummy.py` => The optiton is set to True, because defined in the path subcommand. We make the option default to None. This does not override the value defined earlier in the command line.
1 parent b96eb05 commit 71ec8ea

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Removed
9+
10+
- A bullet item for the Removed category.
11+
12+
-->
13+
<!--
14+
### Added
15+
16+
- A bullet item for the Added category.
17+
18+
-->
19+
<!--
20+
### Changed
21+
22+
- A bullet item for the Changed category.
23+
24+
-->
25+
<!--
26+
### Deprecated
27+
28+
- A bullet item for the Deprecated category.
29+
30+
-->
31+
32+
### Fixed
33+
34+
- We add a default value None to the click option `with-incident-details` to fix the behavior of the option.
35+
<!--
36+
37+
### Security
38+
39+
- A bullet item for the Security category.
40+
41+
-->

ggshield/cmd/secret/scan/secret_scan_common_options.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def _exclude_callback(
9595
_ignore_known_secrets_option = click.option(
9696
"--ignore-known-secrets",
9797
is_flag=True,
98+
# The default value **must** be set to None.
99+
# Each command or subcommand calls create_config_callback to gather option values.
100+
# If the option is placed early in the command line, the value may be overridden
101+
# later on with False if no default is defined.
98102
default=None,
99103
help="Ignore secrets already known by GitGuardian dashboard.",
100104
callback=create_config_callback("secret", "ignore_known_secrets"),
@@ -124,6 +128,11 @@ def _banlist_detectors_callback(
124128
_with_incident_details_option = click.option(
125129
"--with-incident-details",
126130
is_flag=True,
131+
# The default value **must** be set to None.
132+
# Each command or subcommand calls create_config_callback to gather option values.
133+
# If the option is placed early in the command line, the value may be overridden
134+
# later on with False if no default is defined.
135+
default=None,
127136
help="Display full details about the dashboard incident if one is found (JSON and SARIF formats only).",
128137
callback=create_config_callback("secret", "with_incident_details"),
129138
)

0 commit comments

Comments
 (0)