1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
use colored::Colorize;
use std::io::{self, Write};
use crate::config::{Config, RepositoryConfig};
pub fn add_repository(name: &str, url: &str, mirror: Option<&str>) -> Result<(), String> {
let mut cfg = Config::load();
if cfg.repositories.contains_key(name) {
return Err(format!("Repository '{}' already exists", name));
}
print!(
"{} Enable GPG verification for '{}'? [Y/n]: ",
"[ror]".blue().bold(),
name
);
io::stdout().flush().ok();
let mut answer = String::new();
io::stdin().read_line(&mut answer).ok();
let gpg_support = !answer.trim().eq_ignore_ascii_case("n");
if !gpg_support {
print!(
"{} Repository '{}' will have GPG disabled. It may be unsafe. Continue? [y/N]: ",
"[ror]".yellow().bold(),
name
);
io::stdout().flush().ok();
let mut confirm = String::new();
io::stdin().read_line(&mut confirm).ok();
if !confirm.trim().eq_ignore_ascii_case("y") {
println!("{} Aborted.", "[ror]".yellow());
return Ok(());
}
}
let gpg_key = if gpg_support {
print!("{} GPG key filename (e.g. rorka.pub): ", "[ror]".blue().bold());
io::stdout().flush().ok();
let mut key = String::new();
io::stdin().read_line(&mut key).ok();
let key = key.trim().to_string();
if key.is_empty() { None } else { Some(key) }
} else {
None
};
let repo = RepositoryConfig {
url: url.to_string(),
urlrepo: None,
mirror: mirror.map(String::from),
gpg_support,
gpg_key,
};
cfg.repositories.insert(name.to_string(), repo);
cfg.save().map_err(|e| format!("Failed to save config: {}", e))?;
println!("{} Repository '{}' added.", "[ror]".green().bold(), name);
Ok(())
}
pub fn remove_repository(name: &str) -> Result<(), String> {
let mut cfg = Config::load();
if !cfg.repositories.contains_key(name) {
return Err(format!("Repository '{}' not found", name));
}
cfg.repositories.remove(name);
cfg.save().map_err(|e| format!("Failed to save config: {}", e))?;
println!("{} Repository '{}' removed.", "[ror]".green().bold(), name);
Ok(())
}
pub fn list_repositories() {
let cfg = Config::load();
if cfg.repositories.is_empty() {
println!("{} No repositories configured.", "[ror]".yellow());
return;
}
println!("{} Configured repositories:", "[ror]".blue().bold());
for (name, repo) in &cfg.repositories {
println!(" {} {}", name.green(), repo.url);
if let Some(m) = &repo.mirror {
println!(" mirror: {}", m);
}
if repo.gpg_support {
let key = repo.gpg_key.as_deref().unwrap_or("none");
println!(" gpg: {} (key: {})", "enabled".green(), key.cyan());
} else {
println!(" gpg: {}", "disabled".red().bold());
}
}
}
|