Skip to content

Commit 60eebc1

Browse files
committed
fix(plugin): add verbose remove output
1 parent 7954d02 commit 60eebc1

3 files changed

Lines changed: 75 additions & 7 deletions

File tree

src/cortex-cli/src/agent_cmd/tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
#[cfg(test)]
44
mod tests {
55
use crate::agent_cmd::cli::{CopyArgs, ExportArgs};
6-
use crate::agent_cmd::loader::{
7-
load_builtin_agents, parse_frontmatter, read_file_with_encoding,
8-
};
6+
use crate::agent_cmd::loader::{load_builtin_agents, parse_frontmatter};
97
use crate::agent_cmd::types::AgentMode;
8+
use crate::utils::file::read_file_with_encoding;
109

1110
#[test]
1211
fn test_read_file_with_utf8() {

src/cortex-cli/src/cli/handlers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use crate::styled_output::{print_info, print_success, print_warning};
1919
///
2020
/// This is the main command router for the CLI.
2121
pub async fn dispatch_command(cli: Cli) -> Result<()> {
22+
let verbose = cli.verbose;
23+
2224
match cli.command {
2325
None => run_tui(cli.interactive).await,
2426
Some(Commands::Init(init_cli)) => run_init(init_cli).await,
@@ -58,7 +60,7 @@ pub async fn dispatch_command(cli: Cli) -> Result<()> {
5860
Some(Commands::Debug(debug_cli)) => debug_cli.run().await,
5961
Some(Commands::Servers(servers_cli)) => run_servers(servers_cli).await,
6062
Some(Commands::History(history_cli)) => run_history(history_cli).await,
61-
Some(Commands::Plugin(plugin_cli)) => plugin_cli.run().await,
63+
Some(Commands::Plugin(plugin_cli)) => plugin_cli.run(verbose).await,
6264
Some(Commands::Feedback(feedback_cli)) => feedback_cli.run().await,
6365
Some(Commands::Lock(lock_cli)) => lock_cli.run().await,
6466
Some(Commands::Alias(alias_cli)) => alias_cli.run().await,

src/cortex-cli/src/plugin_cmd.rs

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,11 +939,11 @@ cp plugin.toml ~/.cortex/plugins/{}/
939939

940940
impl 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,
946-
PluginSubcommand::Remove(args) => run_remove(args).await,
946+
PluginSubcommand::Remove(args) => run_remove(args, verbose).await,
947947
PluginSubcommand::Enable(args) => run_enable(args).await,
948948
PluginSubcommand::Disable(args) => run_disable(args).await,
949949
PluginSubcommand::Show(args) => run_show(args).await,
@@ -1143,7 +1143,7 @@ fn copy_dir_recursive(src: &std::path::Path, dst: &std::path::Path) -> Result<()
11431143
Ok(())
11441144
}
11451145

1146-
async fn run_remove(args: PluginRemoveArgs) -> Result<()> {
1146+
async fn run_remove(args: PluginRemoveArgs, verbose: bool) -> Result<()> {
11471147
let plugins_dir = get_plugins_dir();
11481148
let plugin_path = plugins_dir.join(&args.name);
11491149

@@ -1164,11 +1164,49 @@ async fn run_remove(args: PluginRemoveArgs) -> Result<()> {
11641164
}
11651165
}
11661166

1167+
if verbose {
1168+
for line in plugin_remove_verbose_preflight_lines(&plugin_path, args.yes) {
1169+
println!("{line}");
1170+
}
1171+
}
1172+
11671173
std::fs::remove_dir_all(&plugin_path)?;
11681174
println!("Plugin '{}' removed successfully.", args.name);
1175+
1176+
if verbose {
1177+
for line in plugin_remove_verbose_completion_lines(&plugin_path, &plugins_dir) {
1178+
println!("{line}");
1179+
}
1180+
}
1181+
11691182
Ok(())
11701183
}
11711184

1185+
fn plugin_remove_verbose_preflight_lines(plugin_path: &Path, yes: bool) -> Vec<String> {
1186+
vec![
1187+
format!("Plugin directory: {}", plugin_path.display()),
1188+
format!(
1189+
"Confirmation: {}",
1190+
if yes {
1191+
"skipped (--yes)"
1192+
} else {
1193+
"confirmed by prompt"
1194+
}
1195+
),
1196+
]
1197+
}
1198+
1199+
fn plugin_remove_verbose_completion_lines(plugin_path: &Path, plugins_dir: &Path) -> Vec<String> {
1200+
vec![
1201+
format!("Removed path: {}", plugin_path.display()),
1202+
format!(
1203+
"Plugin exists after removal: {}",
1204+
if plugin_path.exists() { "yes" } else { "no" }
1205+
),
1206+
format!("Plugins directory: {}", plugins_dir.display()),
1207+
]
1208+
}
1209+
11721210
async fn run_enable(args: PluginEnableArgs) -> Result<()> {
11731211
let plugins_dir = get_plugins_dir();
11741212
let plugin_path = plugins_dir.join(&args.name);
@@ -2458,6 +2496,35 @@ mod tests {
24582496
assert!(args.yes, "yes should be true when set");
24592497
}
24602498

2499+
#[test]
2500+
fn test_plugin_remove_verbose_lines_include_extra_context() {
2501+
let plugins_dir = PathBuf::from("cortex-plugins");
2502+
let plugin_path = plugins_dir.join("remove-me");
2503+
2504+
let preflight = plugin_remove_verbose_preflight_lines(&plugin_path, true);
2505+
assert_eq!(
2506+
preflight,
2507+
vec![
2508+
format!("Plugin directory: {}", plugin_path.display()),
2509+
"Confirmation: skipped (--yes)".to_string(),
2510+
]
2511+
);
2512+
2513+
let completion = plugin_remove_verbose_completion_lines(&plugin_path, &plugins_dir);
2514+
assert!(
2515+
completion
2516+
.iter()
2517+
.any(|line| line == &format!("Removed path: {}", plugin_path.display())),
2518+
"completion output should include the removed plugin path"
2519+
);
2520+
assert!(
2521+
completion
2522+
.iter()
2523+
.any(|line| line == &format!("Plugins directory: {}", plugins_dir.display())),
2524+
"completion output should include the parent plugin directory"
2525+
);
2526+
}
2527+
24612528
// ==========================================================================
24622529
// CLI argument parsing tests - PluginEnableArgs / PluginDisableArgs
24632530
// ==========================================================================

0 commit comments

Comments
 (0)