logo
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! When wasmer self-update is executed, this is what gets executed
use anyhow::{Context, Result};
#[cfg(not(target_os = "windows"))]
use std::process::{Command, Stdio};
use structopt::StructOpt;

/// The options for the `wasmer self-update` subcommand
#[derive(Debug, StructOpt)]
pub struct SelfUpdate {}

impl SelfUpdate {
    /// Runs logic for the `self-update` subcommand
    pub fn execute(&self) -> Result<()> {
        self.inner_execute().context("failed to self-update wasmer")
    }

    #[cfg(not(target_os = "windows"))]
    fn inner_execute(&self) -> Result<()> {
        println!("Fetching latest installer");
        let cmd = Command::new("curl")
            .arg("https://get.wasmer.io")
            .arg("-sSfL")
            .stdout(Stdio::piped())
            .spawn()?;

        let mut process = Command::new("sh")
            .stdin(cmd.stdout.unwrap())
            .stdout(Stdio::inherit())
            .spawn()?;

        process.wait().unwrap();
        Ok(())
    }

    #[cfg(target_os = "windows")]
    fn inner_execute(&self) -> Result<()> {
        bail!("Self update is not supported on Windows. Use install instructions on the Wasmer homepage: https://wasmer.io");
    }
}