noxis cli protocol now developed

pull/19/head
prplV 2025-01-09 15:10:34 +03:00
parent 8b123cd593
commit 014e8dd56d
3 changed files with 12 additions and 11 deletions

View File

@ -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<String>,
}
#[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",

View File

@ -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(())
}

View File

@ -11,14 +11,17 @@ pub async fn create_tcp_stream() -> Result<TcpStream> {
}
pub async fn try_send(stream: Result<TcpStream>, 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(&params)?;
// 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;