roboticus_cli/cli/admin/misc/
local_commands.rs1pub fn cmd_completion(shell: &str) -> Result<(), Box<dyn std::error::Error>> {
2 match shell {
3 "bash" => {
4 println!("# Roboticus bash completion");
5 println!("# Add to ~/.bashrc: eval \"$(roboticus completion bash)\"");
6 println!(
7 "complete -W \"agents auth channels check circuit completion config daemon defrag ingest init keystore logs mechanic memory metrics migrate models plugins reset schedule security serve sessions setup skills status uninstall update version wallet web\" roboticus"
8 );
9 }
10 "zsh" => {
11 println!("# Roboticus zsh completion");
12 println!("# Add to ~/.zshrc: eval \"$(roboticus completion zsh)\"");
13 println!(
14 "compctl -k \"(agents auth channels check circuit completion config daemon defrag ingest init keystore logs mechanic memory metrics migrate models plugins reset schedule security serve sessions setup skills status uninstall update version wallet web)\" roboticus"
15 );
16 }
17 "fish" => {
18 println!("# Roboticus fish completion");
19 println!("# Run: roboticus completion fish | source");
20 for cmd in [
21 "agents",
22 "auth",
23 "channels",
24 "check",
25 "circuit",
26 "completion",
27 "config",
28 "daemon",
29 "defrag",
30 "ingest",
31 "init",
32 "keystore",
33 "logs",
34 "mechanic",
35 "memory",
36 "metrics",
37 "migrate",
38 "models",
39 "plugins",
40 "reset",
41 "schedule",
42 "security",
43 "serve",
44 "sessions",
45 "setup",
46 "skills",
47 "status",
48 "uninstall",
49 "update",
50 "version",
51 "wallet",
52 "web",
53 ] {
54 println!("complete -c roboticus -a {cmd}");
55 }
56 }
57 _ => {
58 eprintln!("Unsupported shell: {shell}. Use bash, zsh, or fish.");
59 }
60 }
61 Ok(())
62}
63
64pub fn cmd_uninstall(
65 purge: bool,
66 daemon_uninstall: Option<&dyn Fn() -> Result<(), Box<dyn std::error::Error>>>,
67) -> Result<(), Box<dyn std::error::Error>> {
68 let (DIM, BOLD, ACCENT, GREEN, YELLOW, RED, CYAN, RESET, MONO) = colors();
69 let (OK, ACTION, WARN, DETAIL, ERR) = icons();
70 println!("\n {BOLD}Roboticus Uninstall{RESET}\n");
71
72 if let Some(uninstall) = daemon_uninstall {
73 match uninstall() {
74 Ok(()) => println!(" {OK} Daemon service removed"),
75 Err(e) => println!(" {WARN} Daemon removal: {e}"),
76 }
77 }
78
79 if purge {
80 let data_dir = roboticus_core::home_dir().join(".roboticus");
81 if data_dir.exists() {
82 std::fs::remove_dir_all(&data_dir)?;
83 println!(" {OK} Removed {}", data_dir.display());
84 } else {
85 println!(" {WARN} Data directory not found: {}", data_dir.display());
86 }
87 } else {
88 println!(" {DIM}Data preserved at ~/.roboticus/ (use --purge to remove){RESET}");
89 }
90
91 println!("\n {GREEN}Uninstall complete.{RESET} CLI binary remains at current location.\n");
92 Ok(())
93}
94
95pub fn cmd_reset(yes: bool) -> Result<(), Box<dyn std::error::Error>> {
96 let (DIM, BOLD, ACCENT, GREEN, YELLOW, RED, CYAN, RESET, MONO) = colors();
97 let (OK, ACTION, WARN, DETAIL, ERR) = icons();
98 println!("\n {BOLD}Roboticus Reset{RESET}\n");
99
100 if !yes {
101 println!(" This will reset configuration and clear the database.");
102 println!(" Wallet files will be preserved.");
103 println!(" Run with --yes to skip this prompt.\n");
104 print!(" Continue? [y/N] ");
105 use std::io::Write;
106 std::io::stdout().flush()?;
107 let mut input = String::new();
108 std::io::stdin().read_line(&mut input)?;
109 if !input.trim().eq_ignore_ascii_case("y") {
110 println!(" Aborted.");
111 return Ok(());
112 }
113 }
114
115 let roboticus_dir = roboticus_core::home_dir().join(".roboticus");
116
117 let db_path = roboticus_dir.join("state.db");
118 if db_path.exists() {
119 std::fs::remove_file(&db_path)?;
120 println!(" {OK} Database cleared");
121 }
122
123 let db_wal = roboticus_dir.join("state.db-wal");
124 if db_wal.exists() {
125 let _ = std::fs::remove_file(&db_wal);
126 }
127 let db_shm = roboticus_dir.join("state.db-shm");
128 if db_shm.exists() {
129 let _ = std::fs::remove_file(&db_shm);
130 }
131
132 let config_path = roboticus_dir.join("roboticus.toml");
133 if config_path.exists() {
134 std::fs::remove_file(&config_path)?;
135 println!(" {OK} Configuration removed (re-run `roboticus init` to recreate)");
136 }
137
138 let logs_dir = roboticus_dir.join("logs");
139 if logs_dir.exists() {
140 std::fs::remove_dir_all(&logs_dir)?;
141 println!(" {OK} Logs cleared");
142 }
143
144 let wallet_dir = roboticus_dir.join("wallet.json");
145 if wallet_dir.exists() {
146 println!(" {WARN} Wallet preserved: {}", wallet_dir.display());
147 }
148
149 println!("\n {GREEN}Reset complete.{RESET}\n");
150 Ok(())
151}
152