From 014e8dd56d5fde99de3ad211c4f3b1cc5cf5057e Mon Sep 17 00:00:00 2001 From: prplV Date: Thu, 9 Jan 2025 15:10:34 +0300 Subject: [PATCH] noxis cli protocol now developed --- noxis-cli/src/cli.rs | 16 ++++++++-------- noxis-cli/src/main.rs | 2 -- noxis-cli/src/net.rs | 5 ++++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/noxis-cli/src/cli.rs b/noxis-cli/src/cli.rs index 677e721..6c07db6 100644 --- a/noxis-cli/src/cli.rs +++ b/noxis-cli/src/cli.rs @@ -1,6 +1,6 @@ use clap::{Parser, Subcommand}; -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct Cli { #[command( subcommand, @@ -9,7 +9,7 @@ pub struct Cli { command : Commands, } -#[derive(Debug, Subcommand)] +#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)] pub enum Commands { #[command( about = "To get info about current Noxis status", @@ -43,7 +43,7 @@ pub enum Commands { Config(ConfigCommand), } -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct StartAction { #[arg( long="with-flags", @@ -53,13 +53,13 @@ pub struct StartAction { flags : Vec, } -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct ConfigCommand { #[command(subcommand)] action : ConfigAction, } -#[derive(Debug, Subcommand)] +#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)] pub enum ConfigAction { #[command( about = "To change current Noxis configuration", @@ -75,7 +75,7 @@ pub enum ConfigAction { Reset, } -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct LocalConfig { // flag #[arg( @@ -91,7 +91,7 @@ pub struct LocalConfig { config : String, } -#[derive(Debug, Parser)] +#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct ProcessCommand { #[arg( help = "name of needed process", @@ -104,7 +104,7 @@ pub struct ProcessCommand { action : ProcessAction, } -#[derive(Debug, Subcommand)] +#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)] enum ProcessAction { #[command( about = "To get info about current process status", diff --git a/noxis-cli/src/main.rs b/noxis-cli/src/main.rs index 718ec2f..0b9e00f 100644 --- a/noxis-cli/src/main.rs +++ b/noxis-cli/src/main.rs @@ -9,8 +9,6 @@ use anyhow::Result; #[tokio::main] async fn main() -> Result<()>{ let cli = Cli::parse(); - dbg!(&cli); - // println!("{:?}", cli); try_send(create_tcp_stream().await, cli).await?; Ok(()) } diff --git a/noxis-cli/src/net.rs b/noxis-cli/src/net.rs index 1c2e470..2e8c43a 100644 --- a/noxis-cli/src/net.rs +++ b/noxis-cli/src/net.rs @@ -11,14 +11,17 @@ pub async fn create_tcp_stream() -> Result { } pub async fn try_send(stream: Result, params: Cli) -> Result<()> { + use serde_json::to_string; let mut stream = stream?; loop { if stream.writable().await.is_err() { sleep(Duration::from_millis(100)).await; continue; } - let msg = format!("{:?}", params); + // let msg: Cli = from_str(&format!("{:?}", params))?; + let msg= to_string(¶ms)?; // let msg = r"HTTP/1.1 POST\r\nContent-Length: 14\r\nContent-Type: text/plain\r\n\r\nHello, World!@"; + stream.write_all(msg.as_bytes()).await?; // ... break;