hexz_cli/cmd/data/
remote.rs1use super::workspace::Workspace;
4use crate::args::RemoteCommand;
5use anyhow::{Context, Result};
6use colored::Colorize;
7
8pub fn run(action: RemoteCommand) -> Result<()> {
10 let mut ws = Workspace::find(&std::env::current_dir()?)?
11 .context("Not in a hexz workspace (no .hexz found)")?;
12
13 match action {
14 RemoteCommand::Add { name, url } => {
15 let _ = ws.config.remotes.insert(name.clone(), url.clone());
16 ws.save()?;
17 println!(
18 " {} Added remote {} {}",
19 "✓".green(),
20 name.magenta(),
21 format!("({url})").bright_black()
22 );
23 }
24 RemoteCommand::Remove { name } => {
25 if ws.config.remotes.remove(&name).is_some() {
26 ws.save()?;
27 println!(" {} Removed remote {}", "✓".green(), name.magenta());
28 } else {
29 anyhow::bail!("Remote '{name}' not found");
30 }
31 }
32 RemoteCommand::List => {
33 if ws.config.remotes.is_empty() {
34 println!(" {} No remotes configured.", "→".yellow());
35 } else {
36 println!("{} Remotes", "╭".dimmed());
37 let count = ws.config.remotes.len();
38 for (i, (name, url)) in ws.config.remotes.iter().enumerate() {
39 let prefix = if i == count - 1 {
40 "╰".dimmed()
41 } else {
42 "│".dimmed()
43 };
44 println!("{} {} {}", prefix, name.magenta(), url.bright_black());
45 }
46 }
47 }
48 }
49
50 Ok(())
51}