@@ -21,6 +21,8 @@ use std::process::{Command, Stdio};
2121use std:: sync:: mpsc;
2222use std:: time:: Duration ;
2323
24+ const PLUGIN_LIST_FILTER_CONFLICT : & str = "Cannot specify both --enabled and --disabled. Choose one filter or use neither for all plugins." ;
25+
2426// =============================================================================
2527// Plugin SDK Templates (embedded for standalone CLI operation)
2628// =============================================================================
@@ -959,9 +961,14 @@ impl PluginCli {
959961async fn run_list ( args : PluginListArgs ) -> Result < ( ) > {
960962 // Validate mutually exclusive flags
961963 if args. enabled && args. disabled {
962- bail ! (
963- "Cannot specify both --enabled and --disabled. Choose one filter or use neither for all plugins."
964- ) ;
964+ if args. json {
965+ println ! (
966+ "{}" ,
967+ serde_json:: to_string_pretty( & plugin_list_filter_conflict_error( ) ) ?
968+ ) ;
969+ std:: process:: exit ( 1 ) ;
970+ }
971+ bail ! ( PLUGIN_LIST_FILTER_CONFLICT ) ;
965972 }
966973
967974 let plugins_dir = get_plugins_dir ( ) ;
@@ -1062,6 +1069,12 @@ async fn run_list(args: PluginListArgs) -> Result<()> {
10621069 Ok ( ( ) )
10631070}
10641071
1072+ fn plugin_list_filter_conflict_error ( ) -> serde_json:: Value {
1073+ serde_json:: json!( {
1074+ "error" : PLUGIN_LIST_FILTER_CONFLICT
1075+ } )
1076+ }
1077+
10651078async fn run_install ( args : PluginInstallArgs ) -> Result < ( ) > {
10661079 // Validate plugin name is not empty (Issue #3700)
10671080 if args. name . trim ( ) . is_empty ( ) {
@@ -2370,6 +2383,18 @@ mod tests {
23702383 assert ! ( args. disabled, "disabled filter should be true when set" ) ;
23712384 }
23722385
2386+ #[ test]
2387+ fn test_plugin_list_filter_conflict_error_serializes_as_json ( ) {
2388+ let error = plugin_list_filter_conflict_error ( ) ;
2389+ let json = serde_json:: to_string ( & error) . expect ( "should serialize conflict error" ) ;
2390+
2391+ assert ! ( json. contains( "error" ) , "JSON should contain error field" ) ;
2392+ assert ! (
2393+ json. contains( PLUGIN_LIST_FILTER_CONFLICT ) ,
2394+ "JSON should contain conflict message"
2395+ ) ;
2396+ }
2397+
23732398 // ==========================================================================
23742399 // CLI argument parsing tests - PluginInstallArgs
23752400 // ==========================================================================
0 commit comments