| 2671 | } |
| 2672 | |
| 2673 | async fn handle_uninstall_command( |
| 2674 | keep_config: bool, |
| 2675 | keep_data: bool, |
| 2676 | dry_run: bool, |
| 2677 | force: bool, |
| 2678 | ) -> anyhow::Result<()> { |
| 2679 | let mut targets = vec![ |
| 2680 | ("data", dirs::data_local_dir().map(|p| p.join("opencode"))), |
| 2681 | ("cache", dirs::cache_dir().map(|p| p.join("opencode"))), |
| 2682 | ("config", dirs::config_dir().map(|p| p.join("opencode"))), |
| 2683 | ("state", dirs::state_dir().map(|p| p.join("opencode"))), |
| 2684 | ]; |
| 2685 | |
| 2686 | println!("Uninstall targets:"); |
| 2687 | for (label, path) in &targets { |
| 2688 | if let Some(path) = path { |
| 2689 | println!(" {:<8} {}", label, path.display()); |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | if dry_run { |
| 2694 | println!("Dry run mode, no files removed."); |
| 2695 | return Ok(()); |
| 2696 | } |
| 2697 | |
| 2698 | if !force { |
| 2699 | println!("Use --force to perform removal."); |
| 2700 | return Ok(()); |
| 2701 | } |
| 2702 | |
| 2703 | for (label, path) in targets.drain(..) { |
| 2704 | let Some(path) = path else { |
| 2705 | continue; |
| 2706 | }; |
| 2707 | if (label == "config" && keep_config) || (label == "data" && keep_data) { |
| 2708 | println!("Skipping {} ({})", label, path.display()); |
| 2709 | continue; |
| 2710 | } |
| 2711 | if path.exists() { |
| 2712 | fs::remove_dir_all(&path) |
| 2713 | .map_err(|e| anyhow::anyhow!("Failed removing {}: {}", path.display(), e))?; |
| 2714 | println!("Removed {}", path.display()); |
| 2715 | } |
| 2716 | } |
| 2717 | Ok(()) |
| 2718 | } |
| 2719 | |
| 2720 | async fn handle_generate_command() -> anyhow::Result<()> { |
| 2721 | let mut paths: HashMap<String, serde_json::Map<String, serde_json::Value>> = HashMap::new(); |