@@ -939,12 +939,12 @@ cp plugin.toml ~/.cortex/plugins/{}/
939939
940940impl PluginCli {
941941 /// Run the plugin command.
942- pub async fn run ( self ) -> Result < ( ) > {
942+ pub async fn run ( self , verbose : bool ) -> Result < ( ) > {
943943 match self . subcommand {
944944 PluginSubcommand :: List ( args) => run_list ( args) . await ,
945945 PluginSubcommand :: Install ( args) => run_install ( args) . await ,
946946 PluginSubcommand :: Remove ( args) => run_remove ( args) . await ,
947- PluginSubcommand :: Enable ( args) => run_enable ( args) . await ,
947+ PluginSubcommand :: Enable ( args) => run_enable ( args, verbose ) . await ,
948948 PluginSubcommand :: Disable ( args) => run_disable ( args) . await ,
949949 PluginSubcommand :: Show ( args) => run_show ( args) . await ,
950950 PluginSubcommand :: New ( args) => run_new ( args) . await ,
@@ -1169,7 +1169,30 @@ async fn run_remove(args: PluginRemoveArgs) -> Result<()> {
11691169 Ok ( ( ) )
11701170}
11711171
1172- async fn run_enable ( args : PluginEnableArgs ) -> Result < ( ) > {
1172+ fn plugin_enabled_value ( manifest : & toml:: Value ) -> Option < bool > {
1173+ manifest. get ( "enabled" ) . and_then ( |value| value. as_bool ( ) )
1174+ }
1175+
1176+ fn format_enable_verbose_output (
1177+ plugin_path : & Path ,
1178+ manifest_path : & Path ,
1179+ previous_enabled : Option < bool > ,
1180+ current_enabled : bool ,
1181+ ) -> String {
1182+ let previous = previous_enabled
1183+ . map ( |value| value. to_string ( ) )
1184+ . unwrap_or_else ( || "not set" . to_string ( ) ) ;
1185+
1186+ format ! (
1187+ " Plugin directory: {}\n Manifest path: {}\n Previous enabled: {}\n Current enabled: {}" ,
1188+ plugin_path. display( ) ,
1189+ manifest_path. display( ) ,
1190+ previous,
1191+ current_enabled
1192+ )
1193+ }
1194+
1195+ async fn run_enable ( args : PluginEnableArgs , verbose : bool ) -> Result < ( ) > {
11731196 let plugins_dir = get_plugins_dir ( ) ;
11741197 let plugin_path = plugins_dir. join ( & args. name ) ;
11751198 let manifest_path = plugin_path. join ( "plugin.toml" ) ;
@@ -1180,13 +1203,20 @@ async fn run_enable(args: PluginEnableArgs) -> Result<()> {
11801203
11811204 let content = std:: fs:: read_to_string ( & manifest_path) ?;
11821205 let mut manifest: toml:: Value = toml:: from_str ( & content) ?;
1206+ let previous_enabled = plugin_enabled_value ( & manifest) ;
11831207
11841208 if let Some ( table) = manifest. as_table_mut ( ) {
11851209 table. insert ( "enabled" . to_string ( ) , toml:: Value :: Boolean ( true ) ) ;
11861210 }
11871211
11881212 std:: fs:: write ( & manifest_path, toml:: to_string_pretty ( & manifest) ?) ?;
11891213 println ! ( "Plugin '{}' enabled." , args. name) ;
1214+ if verbose {
1215+ println ! (
1216+ "{}" ,
1217+ format_enable_verbose_output( & plugin_path, & manifest_path, previous_enabled, true )
1218+ ) ;
1219+ }
11901220 Ok ( ( ) )
11911221}
11921222
@@ -2471,6 +2501,26 @@ mod tests {
24712501 assert_eq ! ( args. name, "enable-me" , "name should match" ) ;
24722502 }
24732503
2504+ #[ test]
2505+ fn test_plugin_enable_verbose_output_adds_diagnostics ( ) {
2506+ let plugin_path = PathBuf :: from ( "/home/user/.cortex/plugins/sample-one" ) ;
2507+ let manifest_path = plugin_path. join ( "plugin.toml" ) ;
2508+
2509+ let default_output = "Plugin 'sample-one' enabled." . to_string ( ) ;
2510+ let verbose_details =
2511+ format_enable_verbose_output ( & plugin_path, & manifest_path, Some ( false ) , true ) ;
2512+ let verbose_output = format ! ( "{default_output}\n {verbose_details}" ) ;
2513+
2514+ assert_ne ! (
2515+ default_output, verbose_output,
2516+ "verbose enable output should differ from default output"
2517+ ) ;
2518+ assert ! ( verbose_output. contains( "Plugin directory:" ) ) ;
2519+ assert ! ( verbose_output. contains( "Manifest path:" ) ) ;
2520+ assert ! ( verbose_output. contains( "Previous enabled: false" ) ) ;
2521+ assert ! ( verbose_output. contains( "Current enabled: true" ) ) ;
2522+ }
2523+
24742524 #[ test]
24752525 fn test_plugin_disable_args ( ) {
24762526 let args = PluginDisableArgs {
0 commit comments