Breaking websocket functionality out into its own module
This commit is contained in:
@@ -1,20 +1,9 @@
|
||||
use clap::{arg, Parser, Subcommand};
|
||||
use clap::Parser;
|
||||
use clap::Subcommand;
|
||||
|
||||
pub(crate) fn parse_args() -> Args {
|
||||
let args = Args::parse();
|
||||
|
||||
match &args.command {
|
||||
Some(Commands::Init { init }) => {
|
||||
if *init {
|
||||
println!("Initializing Side Node")
|
||||
}
|
||||
}
|
||||
Some(Commands::Run {}) => {
|
||||
println!("Running side node")
|
||||
}
|
||||
None => todo!(),
|
||||
}
|
||||
|
||||
args
|
||||
}
|
||||
|
||||
@@ -23,16 +12,12 @@ pub(crate) fn parse_args() -> Args {
|
||||
#[command(version, about, long_about = None)]
|
||||
pub(crate) struct Args {
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
pub(crate) command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
pub(crate) enum Commands {
|
||||
/// runs the Side Node
|
||||
Run {},
|
||||
Init {
|
||||
/// initializes a Side Node with a config file and keypair
|
||||
#[arg(short, long)]
|
||||
init: bool,
|
||||
},
|
||||
Init {},
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
use cli::parse_args;
|
||||
use websockets::{WebSocket, WebSocketError};
|
||||
use cli::{parse_args, Commands};
|
||||
|
||||
pub(crate) mod cli;
|
||||
pub(crate) mod websocket;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), WebSocketError> {
|
||||
parse_args();
|
||||
let mut ws = WebSocket::connect("ws://localhost:8080/").await?;
|
||||
async fn main() {
|
||||
let args = parse_args();
|
||||
|
||||
ws.send_text("foo".to_string()).await?;
|
||||
// ws.receive().await?;
|
||||
// ws.close(None).await?;
|
||||
loop {
|
||||
let msg = ws.receive().await?;
|
||||
println!("Received: {:?}", msg);
|
||||
match &args.command {
|
||||
Some(Commands::Init {}) => {
|
||||
println!("Initializing Side Node")
|
||||
}
|
||||
Some(Commands::Run {}) => {
|
||||
websocket::start().await.unwrap();
|
||||
}
|
||||
None => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
13
side-node/src/websocket/mod.rs
Normal file
13
side-node/src/websocket/mod.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use websockets::WebSocket;
|
||||
|
||||
pub(crate) async fn start() -> Result<(), websockets::WebSocketError> {
|
||||
let mut ws = WebSocket::connect("ws://localhost:8080/").await?;
|
||||
|
||||
ws.send_text("foo".to_string()).await?;
|
||||
// ws.receive().await?;
|
||||
// ws.close(None).await?;
|
||||
loop {
|
||||
let msg = ws.receive().await?;
|
||||
println!("Received: {:?}", msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user