From 344af3ff7c9493b4e2c6eee134b9b341eaabf736 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Tue, 7 Nov 2023 12:58:12 +0100 Subject: add ping support and readable output --- src/error.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index d35991b..27fc7a6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,6 +4,7 @@ pub enum CliError { Reqwest(reqwest::Error), Config(config::ConfigError), Serde(serde_json::Error), + WsResponse, } impl Debug for CliError { @@ -12,6 +13,7 @@ impl Debug for CliError { Self::Reqwest(err) => { err.fmt(f) }, Self::Config(err) => { err.fmt(f) }, Self::Serde(err) => { err.fmt(f) }, + Self::WsResponse => { f.write_str("Error in Response") }, } } } -- cgit v1.2.3 From 9957da9b182ca209ff8caa8f670d3bd7eff154bb Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Fri, 10 Nov 2023 12:23:31 +0100 Subject: add basic eta --- docker-compose.yml | 2 +- src/error.rs | 4 +++- src/main.rs | 6 +++--- src/requests/start.rs | 19 +++++++++++++++---- 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src/error.rs') diff --git a/docker-compose.yml b/docker-compose.yml index 0a52d16..3a0ade5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: webol: - image: ghcr.io/fxqnlr/webol:dev-2 + image: ghcr.io/fxqnlr/webol:dev-6 container_name: webol restart: no depends_on: diff --git a/src/error.rs b/src/error.rs index 27fc7a6..f15c60a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,9 +1,10 @@ -use std::fmt::Debug; +use std::{fmt::Debug, num::ParseIntError}; pub enum CliError { Reqwest(reqwest::Error), Config(config::ConfigError), Serde(serde_json::Error), + Parse(ParseIntError), WsResponse, } @@ -13,6 +14,7 @@ impl Debug for CliError { Self::Reqwest(err) => { err.fmt(f) }, Self::Config(err) => { err.fmt(f) }, Self::Serde(err) => { err.fmt(f) }, + Self::Parse(err) => { err.fmt(f) }, Self::WsResponse => { f.write_str("Error in Response") }, } } diff --git a/src/main.rs b/src/main.rs index d7c985f..204e671 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,9 @@ mod config; mod error; mod requests; -static OVERVIEW_STYLE: &str = "{spinner:.green} {wide_msg}({elapsed})"; -static OVERVIEW_ERROR: &str = "✗ {wide_msg}({elapsed})"; -static OVERVIEW_DONE: &str = "✓ {wide_msg}({elapsed})"; +static OVERVIEW_STYLE: &str = "{spinner:.green} ({elapsed}{wide_msg}"; +static OVERVIEW_ERROR: &str = "✗ ({elapsed}) {wide_msg}"; +static OVERVIEW_DONE: &str = "✓ ({elapsed}) {wide_msg}"; static DEFAULT_STYLE: &str = " {spinner:.green} {wide_msg}"; static DONE_STYLE: &str = " ✓ {wide_msg}"; static ERROR_STYLE: &str = " ✗ {wide_msg}"; diff --git a/src/requests/start.rs b/src/requests/start.rs index 882b154..ca4ca44 100644 --- a/src/requests/start.rs +++ b/src/requests/start.rs @@ -1,5 +1,5 @@ use futures_util::{StreamExt, SinkExt}; -use indicatif::MultiProgress; +use indicatif::{MultiProgress, ProgressBar}; use reqwest::StatusCode; use serde::Deserialize; use tokio_tungstenite::{connect_async, tungstenite::Message}; @@ -9,7 +9,7 @@ use crate::{error::CliError, default_headers, ErrorResponse, format_url, Protoco pub async fn start(id: String, ping: bool) -> Result<(), CliError> { let send_start = MultiProgress::new(); - let overview = add_pb(&send_start, OVERVIEW_STYLE, format!("start {}", id)); + let overview = add_pb(&send_start, OVERVIEW_STYLE, format!(") start {}", id)); // TODO: calculate average start-time on server let url = format_url("start", Protocols::Http)?; @@ -38,7 +38,7 @@ pub async fn start(id: String, ping: bool) -> Result<(), CliError> { } if ping { - let status = status_socket(body.uuid, &send_start).await?; + let status = status_socket(body.uuid, &send_start, &overview, id).await?; if status { finish_pb(overview, format!("successfully started {}", body.id), OVERVIEW_DONE); } else { @@ -59,7 +59,7 @@ pub async fn start(id: String, ping: bool) -> Result<(), CliError> { Ok(()) } -async fn status_socket(uuid: String, pb: &MultiProgress) -> Result { +async fn status_socket(uuid: String, pb: &MultiProgress, overview: &ProgressBar, id: String) -> Result { // TODO: Remove unwraps let ws_pb = add_pb(pb, DEFAULT_STYLE, "connect to websocket".to_string()); let (mut ws_stream, _response) = connect_async(format_url("status", Protocols::Websocket)?) @@ -68,6 +68,11 @@ async fn status_socket(uuid: String, pb: &MultiProgress) -> Result Result Result { + let spl: Vec<&str> = msg.split('_').collect(); + if (spl[0] != "eta") || (spl[2] != uuid) { return Err(CliError::WsResponse); }; + Ok(u64::from_str_radix(spl[1], 10).map_err(CliError::Parse)?) +} + fn verify_response(res: String, org_uuid: String) -> Result { let spl: Vec<&str> = res.split('_').collect(); let res_type = spl[0]; -- cgit v1.2.3