noxis cli protocol now developed
parent
8b123cd593
commit
014e8dd56d
|
|
@ -1,6 +1,6 @@
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
#[command(
|
#[command(
|
||||||
subcommand,
|
subcommand,
|
||||||
|
|
@ -9,7 +9,7 @@ pub struct Cli {
|
||||||
command : Commands,
|
command : Commands,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
#[command(
|
#[command(
|
||||||
about = "To get info about current Noxis status",
|
about = "To get info about current Noxis status",
|
||||||
|
|
@ -43,7 +43,7 @@ pub enum Commands {
|
||||||
Config(ConfigCommand),
|
Config(ConfigCommand),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct StartAction {
|
pub struct StartAction {
|
||||||
#[arg(
|
#[arg(
|
||||||
long="with-flags",
|
long="with-flags",
|
||||||
|
|
@ -53,13 +53,13 @@ pub struct StartAction {
|
||||||
flags : Vec<String>,
|
flags : Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ConfigCommand {
|
pub struct ConfigCommand {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
action : ConfigAction,
|
action : ConfigAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum ConfigAction {
|
pub enum ConfigAction {
|
||||||
#[command(
|
#[command(
|
||||||
about = "To change current Noxis configuration",
|
about = "To change current Noxis configuration",
|
||||||
|
|
@ -75,7 +75,7 @@ pub enum ConfigAction {
|
||||||
Reset,
|
Reset,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct LocalConfig {
|
pub struct LocalConfig {
|
||||||
// flag
|
// flag
|
||||||
#[arg(
|
#[arg(
|
||||||
|
|
@ -91,7 +91,7 @@ pub struct LocalConfig {
|
||||||
config : String,
|
config : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ProcessCommand {
|
pub struct ProcessCommand {
|
||||||
#[arg(
|
#[arg(
|
||||||
help = "name of needed process",
|
help = "name of needed process",
|
||||||
|
|
@ -104,7 +104,7 @@ pub struct ProcessCommand {
|
||||||
action : ProcessAction,
|
action : ProcessAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)]
|
||||||
enum ProcessAction {
|
enum ProcessAction {
|
||||||
#[command(
|
#[command(
|
||||||
about = "To get info about current process status",
|
about = "To get info about current process status",
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ use anyhow::Result;
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()>{
|
async fn main() -> Result<()>{
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
dbg!(&cli);
|
|
||||||
// println!("{:?}", cli);
|
|
||||||
try_send(create_tcp_stream().await, cli).await?;
|
try_send(create_tcp_stream().await, cli).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,17 @@ pub async fn create_tcp_stream() -> Result<TcpStream> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn try_send(stream: Result<TcpStream>, params: Cli) -> Result<()> {
|
pub async fn try_send(stream: Result<TcpStream>, params: Cli) -> Result<()> {
|
||||||
|
use serde_json::to_string;
|
||||||
let mut stream = stream?;
|
let mut stream = stream?;
|
||||||
loop {
|
loop {
|
||||||
if stream.writable().await.is_err() {
|
if stream.writable().await.is_err() {
|
||||||
sleep(Duration::from_millis(100)).await;
|
sleep(Duration::from_millis(100)).await;
|
||||||
continue;
|
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!@";
|
// 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?;
|
stream.write_all(msg.as_bytes()).await?;
|
||||||
// ...
|
// ...
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue