Skip to content

Commit

Permalink
Merge pull request #1 from MisterBourbaki/cli
Browse files Browse the repository at this point in the history
Add a CLI
  • Loading branch information
MisterBourbaki authored Dec 4, 2024
2 parents 0f5d2a8 + a68dcc6 commit 86cc798
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 4 deletions.
114 changes: 114 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ numpy = "0.23"
component = "0.1.1"
fmt = "0.1.0"
clippy = "0.0.302"
clap = { version = "4.5.21", features = ["derive"] }

[build-dependencies]
tonic-build = "*"
Expand Down
28 changes: 25 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,30 @@ use tonic::Request;
use routeguide::route_guide_client::RouteGuideClient;
use routeguide::{Point, Rectangle, RouteNote, SomeDims};

use clap::Parser;

pub mod routeguide {
tonic::include_proto!("routeguide");
}

/// Simple structure for arguments of the client CLI.
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Dimension of the vectors
#[arg(short, long)]
dim_vec: i32,

/// Number of vectors
#[arg(short, long, default_value_t = 1)]
num_vec: i32,

/// Adress of the server
#[arg(short, long, default_value_t=String::from("[::1]:10000"))]
addr: String,
}


async fn print_features(client: &mut RouteGuideClient<Channel>) -> Result<(), Box<dyn Error>> {
let rectangle = Rectangle {
lo: Some(Point {
Expand Down Expand Up @@ -91,7 +111,9 @@ async fn run_route_chat(client: &mut RouteGuideClient<Channel>) -> Result<(), Bo

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = RouteGuideClient::connect("http://[::1]:10000").await?;
let args = Args::parse();
let full_addr = String::from("http://") + &args.addr;
let mut client = RouteGuideClient::connect(full_addr).await?;

println!("*** SIMPLE RPC ***");
let response = client
Expand All @@ -104,8 +126,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let response_bis = client
.get_vectors(Request::new(SomeDims {
dim: 10,
num: 3,
dim: args.dim_vec,
num: args.num_vec,
}))
.await?;
println!("RESPONSE = {:?}", response_bis);
Expand Down
16 changes: 15 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use tonic::{Request, Response, Status};
use routeguide::route_guide_server::{RouteGuide, RouteGuideServer};
use routeguide::{Feature, Point, Rectangle, RouteNote, RouteSummary, SomeDims, NumpyVector, NumpyListVectors};

use clap::Parser;

pub mod routeguide {
tonic::include_proto!("routeguide");
}
Expand All @@ -24,6 +26,15 @@ pub struct RouteGuideService {
features: Arc<Vec<Feature>>,
}

/// Simple structure for arguments of the server CLI.
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Adress for the server to listen to
#[arg(short, long, default_value_t=String::from("[::1]:10000"))]
addr: String,
}

#[tonic::async_trait]
impl RouteGuide for RouteGuideService {
async fn get_feature(&self, request: Request<Point>) -> Result<Response<Feature>, Status> {
Expand Down Expand Up @@ -145,7 +156,10 @@ impl RouteGuide for RouteGuideService {

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:10000".parse().unwrap();

let args = Args::parse();
// let addr = "[::1]:10000".parse().unwrap();
let addr = args.addr.parse().unwrap();

println!("RouteGuideServer listening on: {}", addr);

Expand Down

0 comments on commit 86cc798

Please sign in to comment.