diff --git a/Cargo.lock b/Cargo.lock index 4fee400..44c853f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,6 +203,7 @@ name = "client" version = "0.1.0" dependencies = [ "anyhow", + "clap", "minisql", "parser", "proto", diff --git a/client/Cargo.toml b/client/Cargo.toml index a8012c6..4e060c2 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -11,3 +11,4 @@ anyhow = "1.0.76" proto = { path = "../proto" } minisql = { path = "../minisql" } parser = { path = "../parser" } +clap = { version = "4.4.18", features = ["derive"] } \ No newline at end of file diff --git a/client/src/main.rs b/client/src/main.rs index fc845e9..31d5d82 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -1,3 +1,4 @@ +use clap::Parser; use proto::handshake::client::do_client_handshake; use proto::handshake::request::HandshakeRequest; use proto::reader::protoreader::ProtoReader; @@ -9,9 +10,21 @@ use proto::message::frontend::{FrontendMessage, QueryData}; use proto::reader::oneway::OneWayProtoReader; use proto::writer::oneway::OneWayProtoWriter; +#[derive(Parser)] +struct Cli { + /// Port number of the server. + #[arg(short, long, default_value_t = 5432, help = "Port number of the server")] + port: u16, + + /// Host name or IP address of the server. + #[arg(short, long, default_value = "127.0.0.1", help = "Host name or IP address of the server")] + host: String, +} + #[tokio::main] async fn main() -> anyhow::Result<()> { - let addr = "127.0.0.1:5432"; + let cli = Cli::parse(); + let addr = format!("{}:{}", cli.host, cli.port); let mut stream = TcpStream::connect(addr).await?; let (reader, writer) = stream.split();