aster_cli/commands/
update.rs1use anyhow::Result;
2use std::process::Command;
3
4const DOWNLOAD_SCRIPT_URL: &str =
5 "https://github.com/astercloud/aster-rust/releases/download/stable/download_cli.sh";
6
7pub fn update(canary: bool, reconfigure: bool) -> Result<()> {
8 if cfg!(feature = "disable-update") {
9 anyhow::bail!("This command is disabled");
10 };
11
12 let curl_output = Command::new("curl")
14 .arg("-fsSL")
15 .arg(DOWNLOAD_SCRIPT_URL)
16 .output()?;
17
18 if !curl_output.status.success() {
19 anyhow::bail!(
20 "Failed to download update script: {}",
21 std::str::from_utf8(&curl_output.stderr)?
22 );
23 }
24
25 let shell_str = std::str::from_utf8(&curl_output.stdout)?;
26
27 let update = Command::new("bash")
28 .arg("-c")
29 .arg(shell_str)
30 .env("CANARY", canary.to_string())
31 .env("CONFIGURE", reconfigure.to_string())
32 .env("ASTER_TERMINAL", "1")
33 .spawn()?;
34
35 update.wait_with_output()?;
36
37 Ok(())
38}