Skip to content

Commit 5ac021a

Browse files
committed
improve UX of export options
1 parent cfd2dd1 commit 5ac021a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

cycode/cli/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ def check_latest_version_on_close(ctx: typer.Context) -> None:
6060

6161

6262
def export_if_needed_on_close(ctx: typer.Context) -> None:
63+
scan_finalized = ctx.obj.get('scan_finalized')
6364
printer = ctx.obj.get('console_printer')
64-
if printer.is_recording:
65+
if scan_finalized and printer.is_recording:
6566
printer.export()
6667

6768

cycode/cli/apps/scan/scan_command.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ def scan_command(
9090
'JSON always exports JSON.',
9191
rich_help_panel=_EXPORT_RICH_HELP_PANEL,
9292
),
93-
] = ExportTypeOption.JSON,
93+
] = None,
9494
export_file: Annotated[
9595
Optional[Path],
9696
typer.Option(
9797
'--export-file',
98-
help='Export file. Path to the file where the export will be saved. ',
98+
help='Export file. Path to the file where the export will be saved.',
9999
dir_okay=False,
100100
writable=True,
101101
rich_help_panel=_EXPORT_RICH_HELP_PANEL,
@@ -118,6 +118,17 @@ def scan_command(
118118
"""
119119
add_breadcrumb('scan')
120120

121+
if export_file and export_type is None:
122+
raise typer.BadParameter(
123+
'Export type must be specified when --export-file is provided.',
124+
param_hint='--export-type',
125+
)
126+
if export_type and export_file is None:
127+
raise typer.BadParameter(
128+
'Export file must be specified when --export-type is provided.',
129+
param_hint='--export-file',
130+
)
131+
121132
ctx.obj['show_secret'] = show_secret
122133
ctx.obj['soft_fail'] = soft_fail
123134
ctx.obj['client'] = get_scan_cycode_client(ctx)
@@ -126,7 +137,7 @@ def scan_command(
126137
ctx.obj['severity_threshold'] = severity_threshold
127138
ctx.obj['monitor'] = monitor
128139

129-
if export_file:
140+
if export_type and export_file:
130141
console_printer = ctx.obj['console_printer']
131142
console_printer.enable_recording(export_type, export_file)
132143

@@ -142,7 +153,8 @@ def _sca_scan_to_context(ctx: typer.Context, sca_scan_user_selected: list[str])
142153

143154
@click.pass_context
144155
def scan_command_result_callback(ctx: click.Context, *_, **__) -> None:
145-
add_breadcrumb('scan_finalize')
156+
add_breadcrumb('scan_finalized')
157+
ctx.obj['scan_finalized'] = True
146158

147159
progress_bar = ctx.obj.get('progress_bar')
148160
if progress_bar:

0 commit comments

Comments
 (0)