cuqueclicker_lib/
self_cmd.rs1use anyhow::{Context, Result, bail};
15use std::process::Command;
16
17#[cfg(all(feature = "binary-release", unix))]
18const UNIX_INSTALL_URL: &str =
19 "https://raw.githubusercontent.com/flipbit03/cuqueclicker/main/install.sh";
20#[cfg(all(feature = "binary-release", windows))]
21const WINDOWS_INSTALL_URL: &str =
22 "https://raw.githubusercontent.com/flipbit03/cuqueclicker/main/install.ps1";
23
24#[cfg(feature = "binary-release")]
25pub fn update() -> Result<()> {
26 println!("Updating via installer script...");
27
28 #[cfg(unix)]
29 let status = Command::new("sh")
30 .arg("-c")
31 .arg(format!("curl -fsSL {UNIX_INSTALL_URL} | sh"))
32 .status()
33 .context("failed to spawn sh")?;
34
35 #[cfg(windows)]
36 let status = Command::new("powershell")
37 .args(["-Command", &format!("irm {WINDOWS_INSTALL_URL} | iex")])
38 .status()
39 .context("failed to spawn powershell")?;
40
41 if !status.success() {
42 bail!("update installer exited with status {:?}", status.code());
43 }
44 Ok(())
45}
46
47#[cfg(not(feature = "binary-release"))]
48pub fn update() -> Result<()> {
49 println!("Updating via `cargo install cuqueclicker --force`...");
50 let status = Command::new("cargo")
51 .args(["install", "cuqueclicker", "--force"])
52 .status()
53 .context("failed to spawn cargo (is it on your PATH?)")?;
54 if !status.success() {
55 bail!("cargo install exited with status {:?}", status.code());
56 }
57 Ok(())
58}