summaryrefslogtreecommitdiff
path: root/src/requests/start.rs
blob: 1a8cb6caedb08c6d974e6ba174d8ddf8ace41eba (plain) (blame)
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
use serde::Deserialize;

use crate::{config::SETTINGS, error::CliError, default_headers};

pub fn start(id: String) -> Result<(), CliError> {
    let res = reqwest::blocking::Client::new()
        .post(
            format!(
                "{}/start",
                SETTINGS.get_string("server").map_err(CliError::Config)?
            )
        )
        .headers(default_headers()?)
        .body(
            format!(r#"{{"id": "{}"}}"#, id)
        )
        .send()
        .map_err(CliError::Reqwest)?
        .text();

    let res = serde_json::from_str::<StartResponse>(&res.map_err(CliError::Reqwest)?).map_err(CliError::Serde)?;

    if res.boot {
        println!("successfully started {}", res.id);
    }

    Ok(())
}

#[derive(Debug, Deserialize)]
struct StartResponse {
    boot: bool,
    id: String,
}