1use crate::pkg;
2use crate::utils;
3use anyhow::Result;
4use colored::*;
5
6pub fn run(verbose: bool, fallback: bool, no_pm: bool, no_shell_setup: bool) -> Result<()> {
7 println!("{}", "--- Syncing Package Databases ---".yellow().bold());
8
9 pkg::sync::run(verbose, fallback, no_pm)?;
10
11 println!("{}", "Sync complete.".green());
12
13 if no_shell_setup {
14 return Ok(());
15 }
16
17 println!(
18 "\n{}",
19 "--- Setting up shell completions ---".yellow().bold()
20 );
21 if let Some(shell) = utils::get_current_shell() {
22 println!("Detected shell: {}", shell.to_string().cyan());
23 crate::cmd::shell::run(shell, crate::cli::SetupScope::User)?;
24 } else {
25 println!(
26 "{}",
27 "Could not detect shell. Skipping auto-completion setup.".yellow()
28 );
29 }
30 Ok(())
31}
32
33pub fn set_registry(url_or_keyword: &str) -> Result<()> {
34 let url_storage;
35 let url = match url_or_keyword {
36 "default" => {
37 url_storage = pkg::config::get_default_registry();
38 &url_storage
39 }
40 "gitlab" => "https://gitlab.com/Zillowe/Zillwen/Zusty/Zoidberg.git",
41 "github" => "https://github.com/Zillowe/Zoidberg.git",
42 "codeberg" => "https://codeberg.org/Zillowe/Zoidberg.git",
43 _ => url_or_keyword,
44 };
45
46 pkg::config::set_default_registry(url)?;
47 println!("Default registry set to: {}", url.cyan());
48 println!("The new registry will be used the next time you run 'zoi sync'");
49 Ok(())
50}
51
52pub fn add_registry(url: &str) -> Result<()> {
53 pkg::config::add_added_registry(url)?;
54 println!("Registry '{}' added.", url.cyan());
55 println!("It will be synced on the next 'zoi sync' run.");
56 Ok(())
57}
58
59pub fn remove_registry(handle: &str) -> Result<()> {
60 pkg::config::remove_added_registry(handle)?;
61 println!("Registry '{}' removed.", handle.cyan());
62 Ok(())
63}
64
65pub fn list_registries() -> Result<()> {
66 let config = crate::pkg::config::read_config()?;
67 let db_root = crate::pkg::resolve::get_db_root()?;
68
69 println!("{}", "--- Configured Registries ---".bold());
70
71 if let Some(default) = config.default_registry {
72 let handle = &default.handle;
73 let mut desc = "".to_string();
74 if !handle.is_empty() {
75 let repo_path = db_root.join(handle);
76 if let Ok(repo_config) = crate::pkg::config::read_repo_config(&repo_path) {
77 desc = format!(" - {}", repo_config.description);
78 }
79 }
80 let handle_str = if handle.is_empty() {
81 "<not synced>".italic().to_string()
82 } else {
83 handle.cyan().to_string()
84 };
85 println!("[Set] {}: {}{}", handle_str, default.url, desc);
86 } else {
87 println!("[Set]: <not set>");
88 }
89
90 if !config.added_registries.is_empty() {
91 println!();
92 for reg in config.added_registries {
93 let handle = ®.handle;
94 let mut desc = "".to_string();
95 if !handle.is_empty() {
96 let repo_path = db_root.join(handle);
97 if let Ok(repo_config) = crate::pkg::config::read_repo_config(&repo_path) {
98 desc = format!(" - {}", repo_config.description);
99 }
100 }
101 let handle_str = if handle.is_empty() {
102 "<not synced>".italic().to_string()
103 } else {
104 handle.cyan().to_string()
105 };
106 println!("[Add] {}: {}{}", handle_str, reg.url, desc);
107 }
108 }
109 Ok(())
110}