From 2c76574db7b66f45295c26a615083aebd6f8560f Mon Sep 17 00:00:00 2001 From: Alex van de Sandt Date: Tue, 22 Jan 2019 18:58:37 -0500 Subject: [PATCH] Integrate clap for client --- candid_client/Cargo.toml | 3 +++ candid_client/src/main.rs | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/candid_client/Cargo.toml b/candid_client/Cargo.toml index 7e38a63..3a5df2a 100644 --- a/candid_client/Cargo.toml +++ b/candid_client/Cargo.toml @@ -3,3 +3,6 @@ name = "candid_client" version = "0.1.0" authors = ["Alex van de Sandt "] edition = "2018" + +[dependencies] +clap = "2.32.0" diff --git a/candid_client/src/main.rs b/candid_client/src/main.rs index 0d5b976..c37239b 100644 --- a/candid_client/src/main.rs +++ b/candid_client/src/main.rs @@ -1,11 +1,25 @@ -use std::env; use std::io::prelude::*; use std::io::BufReader; use std::net::TcpStream; +use clap::{App, Arg}; + fn main() { - let args: Vec = env::args().collect(); - let addr = &args[1]; + let matches = App::new("CANdid Client") + .version("0.1.0") + .author("Alex van de Sandt ") + .about("A client to read messages from a CANdid server") + .arg( + Arg::with_name("addr") + .value_name("ADDRESS") + .help("The address:port to connect to") + .takes_value(true) + .required(true), + ) + .get_matches(); + + let addr = matches.value_of("addr").unwrap(); + if let Ok(stream) = TcpStream::connect(addr) { println!("Connected to the server!"); let reader = BufReader::new(stream); -- 2.51.2