diff --git a/Cargo.toml b/Cargo.toml index d84cb69..5b2bfe3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ edition = "2021" clap = { version = "4.0.29", features = ["derive"] } confy = "0.5.1" tungstenite = "0.18.0" +url = "2.3.1" diff --git a/src/main.rs b/src/main.rs index e7a11a9..bed9847 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,51 @@ -fn main() { - println!("Hello, world!"); +use clap::{Parser, ValueEnum}; +use tungstenite::{connect, Message}; +use url::Url; + +const POSSIBLE_COMMANDS: &[&str] = &["play", "pause"]; + +#[derive(ValueEnum, Debug, Clone)] +enum SousaCommands { + Play, + Pause, +} + +#[derive(Parser, Debug)] +#[command(author, version, about, long_about=None)] +struct CliArgs { + /// The IP of the Sousa server. Defaults to 'localhost' + #[arg(long, default_value = "localhost")] + hostname: Option, + + /// The Port of the Sousa server. Defaults to something + #[arg(long, default_value = "9001")] + port: Option, + + /// The command to execute + #[arg(short, long, value_enum)] + action: SousaCommands, +} + +fn main() { + let cli = CliArgs::parse(); + + let (mut socket, resp) = connect( + Url::parse(format!("ws://{}:{}", cli.hostname.unwrap(), cli.port.unwrap()).as_str()) + .unwrap(), + ) + .expect("Couldn't connect to url"); + + println!("Connected to the server"); + println!("Response HTTP code: {}", resp.status()); + println!("Response contains the following headers:"); + for (ref header, _value) in resp.headers() { + println!("* {}", header); + } + + socket + .write_message(Message::Text("Hello WebSocket".into())) + .unwrap(); + //let msg = socket.read_message().expect("Error reading message"); + //println!("Received: {}", msg); + socket.close(None).unwrap(); }