1use crate::error::{CarchError, Result};
2use serde::Deserialize;
3
4#[derive(Deserialize)]
5struct Release {
6 tag_name: String,
7}
8
9pub fn get_current_version() -> String {
10 let version = env!("CARGO_PKG_VERSION");
11 format!("Carch version {version}")
12}
13
14pub fn get_latest_version() -> Result<String> {
15 let client = reqwest::blocking::Client::builder().user_agent("carch").build()?;
16 let response =
17 client.get("https://api.github.com/repos/harilvfs/carch/releases/latest").send()?;
18
19 if !response.status().is_success() {
20 return Err(CarchError::Command("Failed to fetch latest version information".to_string()));
21 }
22
23 let release: Release = response.json()?;
24 let version = release.tag_name.trim_start_matches('v').to_string();
25 Ok(version)
26}