diff options
Diffstat (limited to 'src/requests/start.rs')
-rw-r--r-- | src/requests/start.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/requests/start.rs b/src/requests/start.rs new file mode 100644 index 0000000..1a8cb6c --- /dev/null +++ b/src/requests/start.rs | |||
@@ -0,0 +1,34 @@ | |||
1 | use serde::Deserialize; | ||
2 | |||
3 | use crate::{config::SETTINGS, error::CliError, default_headers}; | ||
4 | |||
5 | pub fn start(id: String) -> Result<(), CliError> { | ||
6 | let res = reqwest::blocking::Client::new() | ||
7 | .post( | ||
8 | format!( | ||
9 | "{}/start", | ||
10 | SETTINGS.get_string("server").map_err(CliError::Config)? | ||
11 | ) | ||
12 | ) | ||
13 | .headers(default_headers()?) | ||
14 | .body( | ||
15 | format!(r#"{{"id": "{}"}}"#, id) | ||
16 | ) | ||
17 | .send() | ||
18 | .map_err(CliError::Reqwest)? | ||
19 | .text(); | ||
20 | |||
21 | let res = serde_json::from_str::<StartResponse>(&res.map_err(CliError::Reqwest)?).map_err(CliError::Serde)?; | ||
22 | |||
23 | if res.boot { | ||
24 | println!("successfully started {}", res.id); | ||
25 | } | ||
26 | |||
27 | Ok(()) | ||
28 | } | ||
29 | |||
30 | #[derive(Debug, Deserialize)] | ||
31 | struct StartResponse { | ||
32 | boot: bool, | ||
33 | id: String, | ||
34 | } | ||