wasmer_cli/commands/
self_update.rs

1use anyhow::Context as _;
2
3/// The options for the `wasmer self-update` subcommand
4#[derive(clap::Parser, Debug)]
5pub struct SelfUpdate {}
6
7impl SelfUpdate {
8    /// Runs logic for the `self-update` subcommand
9    pub fn execute(&self) -> Result<(), anyhow::Error> {
10        self.inner_execute().context("failed to self-update wasmer")
11    }
12
13    #[cfg(not(target_os = "windows"))]
14    fn inner_execute(&self) -> Result<(), anyhow::Error> {
15        use std::process::{Command, Stdio};
16
17        println!("Fetching latest installer");
18        let cmd = Command::new("curl")
19            .arg("https://get.wasmer.io")
20            .arg("-sSfL")
21            .stdout(Stdio::piped())
22            .spawn()?;
23
24        let mut process = Command::new("sh")
25            .stdin(cmd.stdout.unwrap())
26            .stdout(Stdio::inherit())
27            .spawn()?;
28
29        process.wait().unwrap();
30        Ok(())
31    }
32
33    #[cfg(target_os = "windows")]
34    fn inner_execute(&self) -> Result<(), anyhow::Error> {
35        anyhow::bail!(
36            "Self update is not supported on Windows. Use install instructions on the Wasmer homepage: https://wasmer.io"
37        );
38    }
39}