11import os
22from pathlib import Path
3- from typing import Annotated , Optional
3+ from typing import Annotated , Any , Optional
44
55import click
66import typer
2828_SECRET_RICH_HELP_PANEL = 'Secret options'
2929
3030
31+ def _single_value_callback (ctx : typer .Context , param : typer .CallbackParam , value : tuple ) -> Any :
32+ if len (value ) > 1 :
33+ values_str = ', ' .join (str (v ) for v in value )
34+ param_hint = '/' .join (sorted (param .opts , key = len ))
35+ err = typer .BadParameter (
36+ f'Only one value can be specified per command. '
37+ f'Got: { values_str } . '
38+ f'Run a separate command for each value.' ,
39+ ctx = ctx ,
40+ param_hint = param_hint ,
41+ )
42+ err .exit_code = 1
43+ raise err
44+ return value [0 ]
45+
46+
3147def scan_command (
3248 ctx : typer .Context ,
3349 scan_type : Annotated [
@@ -37,6 +53,7 @@ def scan_command(
3753 '-t' ,
3854 help = 'Specify the type of scan you wish to execute.' ,
3955 case_sensitive = False ,
56+ callback = _single_value_callback ,
4057 ),
4158 ] = (ScanTypeOption .SECRET ,),
4259 soft_fail : Annotated [
@@ -126,16 +143,6 @@ def scan_command(
126143 * `cycode scan commit-history <PATH>`: Scan the commit history of a local Git repository.
127144
128145 """
129- if len (scan_type ) > 1 :
130- raise typer .BadParameter (
131- f'Only one scan type can be specified per command. '
132- f'Got: { ", " .join (str (t ) for t in scan_type )} . '
133- f'Run a separate command for each scan type.' ,
134- param_hint = '-t/--scan-type' ,
135- )
136-
137- resolved_scan_type = scan_type [0 ]
138-
139146 if export_file and export_type is None :
140147 raise typer .BadParameter (
141148 'Export type must be specified when --export-file is provided.' ,
@@ -150,7 +157,7 @@ def scan_command(
150157 ctx .obj ['show_secret' ] = show_secret
151158 ctx .obj ['soft_fail' ] = soft_fail
152159 ctx .obj ['stop_on_error' ] = stop_on_error
153- ctx .obj ['scan_type' ] = resolved_scan_type
160+ ctx .obj ['scan_type' ] = scan_type
154161 ctx .obj ['sync' ] = sync
155162 ctx .obj ['severity_threshold' ] = severity_threshold
156163 ctx .obj ['monitor' ] = monitor
@@ -168,9 +175,9 @@ def scan_command(
168175 # Get remote URL from current working directory
169176 remote_url = _try_get_git_remote_url (os .getcwd ())
170177
171- remote_scan_config = scan_client .get_scan_configuration_safe (resolved_scan_type , remote_url )
178+ remote_scan_config = scan_client .get_scan_configuration_safe (scan_type , remote_url )
172179 if remote_scan_config :
173- excluder .apply_scan_config (str (resolved_scan_type ), remote_scan_config )
180+ excluder .apply_scan_config (str (scan_type ), remote_scan_config )
174181
175182 ctx .obj ['scan_config' ] = remote_scan_config
176183
0 commit comments