111 lines
2.7 KiB
Rust
111 lines
2.7 KiB
Rust
use paris::{error, info, success};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::error::Error;
|
|
use std::fmt;
|
|
use tokio::io::AsyncWriteExt;
|
|
use tokio::net::TcpStream;
|
|
use url::Url;
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
enum BuildSystem {
|
|
Cargo,
|
|
Make,
|
|
Custom(String),
|
|
}
|
|
|
|
impl fmt::Display for BuildSystem {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
match self {
|
|
BuildSystem::Cargo => write!(f, "cargo"),
|
|
BuildSystem::Make => write!(f, "make"),
|
|
BuildSystem::Custom(s) => write!(f, "{}", s),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
enum Subcommand {
|
|
Run,
|
|
Build,
|
|
Install,
|
|
Custom(String),
|
|
}
|
|
|
|
impl fmt::Display for Subcommand {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
match self {
|
|
Subcommand::Run => write!(f, "run"),
|
|
Subcommand::Build => write!(f, "build"),
|
|
Subcommand::Install => write!(f, "install"),
|
|
Subcommand::Custom(s) => write!(f, "{}", s),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
enum Tag {
|
|
Release,
|
|
Debug,
|
|
}
|
|
|
|
impl fmt::Display for Tag {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
match self {
|
|
Tag::Release => write!(f, "--release"),
|
|
Tag::Debug => write!(f, "--debug"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
struct Command {
|
|
build_system: BuildSystem,
|
|
subcommand: Subcommand,
|
|
features: Option<Vec<String>>,
|
|
tag: Tag,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
struct Message {
|
|
authentication: Option<String>,
|
|
uuid: Uuid,
|
|
pre_exec: Option<String>,
|
|
profile: bool,
|
|
command: Command,
|
|
repository: Url,
|
|
basename: String,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn Error>> {
|
|
// Connect to a peer
|
|
let mut stream = TcpStream::connect("127.0.0.1:9134").await?;
|
|
success!("Connected to: <green>127.0.0.1:9134<//>");
|
|
|
|
let test_command = Command {
|
|
build_system: BuildSystem::Cargo,
|
|
subcommand: Subcommand::Build,
|
|
features: Some(vec!["one".to_string(), "two".to_string()]),
|
|
tag: Tag::Debug,
|
|
};
|
|
let test_message = Message {
|
|
authentication: Some("test123".to_string()),
|
|
uuid: Uuid::new_v4(),
|
|
pre_exec: None,
|
|
profile: false,
|
|
command: test_command,
|
|
repository: Url::parse("https://lib.rs/crates/serde_json").unwrap(),
|
|
basename: "serde_json".to_string(),
|
|
};
|
|
|
|
let j = serde_json::to_string(&test_message)?;
|
|
stream.write_all(&j.as_bytes()).await?;
|
|
info!(
|
|
"Sent JSON:\n<bright-white>{}<//>",
|
|
serde_json::to_string_pretty(&test_message)?
|
|
);
|
|
|
|
Ok(())
|
|
}
|