Skip to content

Commit

Permalink
chore(interop): Change structopt to clap (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Feb 15, 2022
1 parent dee2ab5 commit a542bf4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
2 changes: 1 addition & 1 deletion interop/Cargo.toml
Expand Up @@ -17,6 +17,7 @@ path = "src/bin/server.rs"
[dependencies]
async-stream = "0.3"
bytes = "1.0"
clap = {version = "3", features = ["derive"]}
console = "0.14"
futures-core = "0.3"
futures-util = "0.3"
Expand All @@ -25,7 +26,6 @@ http-body = "0.4.2"
hyper = "0.14"
prost = "0.9"
prost-derive = "0.9"
structopt = "0.3"
tokio = {version = "1.0", features = ["rt-multi-thread", "time", "macros", "fs"]}
tokio-stream = "0.1"
tonic = {path = "../tonic", features = ["tls"]}
Expand Down
72 changes: 33 additions & 39 deletions interop/src/bin/client.rs
@@ -1,28 +1,23 @@
use clap::Parser;
use interop::client;
use std::time::Duration;
use structopt::{clap::arg_enum, StructOpt};
use tonic::transport::Endpoint;
use tonic::transport::{Certificate, ClientTlsConfig};

#[derive(StructOpt)]
#[derive(Parser)]
struct Opts {
#[structopt(name = "use_tls", long)]
#[clap(name = "use_tls", long)]
use_tls: bool,

#[structopt(
long = "test_case",
use_delimiter = true,
min_values = 1,
possible_values = &Testcase::variants()
)]
#[clap(long = "test_case", use_delimiter = true, min_values = 1, arg_enum)]
test_case: Vec<Testcase>,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
interop::trace_init();

let matches = Opts::from_args();
let matches = Opts::parse();

let test_cases = matches.test_case;

Expand Down Expand Up @@ -98,33 +93,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

arg_enum! {
#[derive(Debug, Copy, Clone)]
#[allow(non_camel_case_types)]
enum Testcase {
empty_unary,
cacheable_unary,
large_unary,
client_compressed_unary,
server_compressed_unary,
client_streaming,
client_compressed_streaming,
server_streaming,
server_compressed_streaming,
ping_pong,
empty_stream,
compute_engine_creds,
jwt_token_creds,
oauth2_auth_token,
per_rpc_creds,
custom_metadata,
status_code_and_message,
special_status_message,
unimplemented_method,
unimplemented_service,
cancel_after_begin,
cancel_after_first_response,
timeout_on_sleeping_server,
concurrent_large_unary
}
#[derive(Debug, Copy, Clone, clap::ArgEnum)]
#[clap(rename_all = "verbatim")]
#[allow(non_camel_case_types)]
enum Testcase {
empty_unary,
cacheable_unary,
large_unary,
client_compressed_unary,
server_compressed_unary,
client_streaming,
client_compressed_streaming,
server_streaming,
server_compressed_streaming,
ping_pong,
empty_stream,
compute_engine_creds,
jwt_token_creds,
oauth2_auth_token,
per_rpc_creds,
custom_metadata,
status_code_and_message,
special_status_message,
unimplemented_method,
unimplemented_service,
cancel_after_begin,
cancel_after_first_response,
timeout_on_sleeping_server,
concurrent_large_unary,
}
8 changes: 4 additions & 4 deletions interop/src/bin/server.rs
@@ -1,19 +1,19 @@
use clap::Parser;
use interop::server;
use structopt::StructOpt;
use tonic::transport::Server;
use tonic::transport::{Identity, ServerTlsConfig};

#[derive(StructOpt)]
#[derive(Parser)]
struct Opts {
#[structopt(name = "use_tls", long)]
#[clap(name = "use_tls", long)]
use_tls: bool,
}

#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
interop::trace_init();

let matches = Opts::from_args();
let matches = Opts::parse();

let addr = "127.0.0.1:10000".parse().unwrap();

Expand Down

0 comments on commit a542bf4

Please sign in to comment.