chore(interop): Use pico-args instead of clap (#1242)
This commit is contained in:
+2
-2
@@ -16,8 +16,8 @@ path = "src/bin/server.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-stream = "0.3"
|
async-stream = "0.3"
|
||||||
clap = {version = ">=4.0.26, <4.1", features = ["derive"]}
|
strum = {version = "0.24", features = ["derive"]}
|
||||||
clap_lex = "=0.3.0" # keeps msrv to 1.60
|
pico-args = {version = "0.5", features = ["eq-separator"]}
|
||||||
console = "0.15"
|
console = "0.15"
|
||||||
futures-core = "0.3"
|
futures-core = "0.3"
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
|
|||||||
+17
-15
@@ -1,29 +1,31 @@
|
|||||||
use clap::{ArgAction, Parser};
|
|
||||||
use interop::client;
|
use interop::client;
|
||||||
use std::time::Duration;
|
use std::{str::FromStr, time::Duration};
|
||||||
use tonic::transport::Endpoint;
|
use tonic::transport::Endpoint;
|
||||||
use tonic::transport::{Certificate, ClientTlsConfig};
|
use tonic::transport::{Certificate, ClientTlsConfig};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Debug)]
|
||||||
struct Opts {
|
struct Opts {
|
||||||
#[clap(name = "use_tls", long, action = ArgAction::SetTrue)]
|
|
||||||
use_tls: bool,
|
use_tls: bool,
|
||||||
|
|
||||||
#[arg(
|
|
||||||
long = "test_case",
|
|
||||||
use_value_delimiter = true,
|
|
||||||
num_args(1..),
|
|
||||||
value_enum,
|
|
||||||
action = ArgAction::Append
|
|
||||||
)]
|
|
||||||
test_case: Vec<Testcase>,
|
test_case: Vec<Testcase>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Opts {
|
||||||
|
fn parse() -> Result<Self, pico_args::Error> {
|
||||||
|
let mut pargs = pico_args::Arguments::from_env();
|
||||||
|
Ok(Self {
|
||||||
|
use_tls: pargs.contains("--use_tls"),
|
||||||
|
test_case: pargs.value_from_fn("--test_case", |test_case| {
|
||||||
|
test_case.split(',').map(Testcase::from_str).collect()
|
||||||
|
})?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
interop::trace_init();
|
interop::trace_init();
|
||||||
|
|
||||||
let matches = Opts::parse();
|
let matches = Opts::parse()?;
|
||||||
|
|
||||||
let test_cases = matches.test_case;
|
let test_cases = matches.test_case;
|
||||||
|
|
||||||
@@ -99,8 +101,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, clap::ValueEnum)]
|
#[derive(Debug, strum::EnumString)]
|
||||||
#[clap(rename_all = "snake_case")]
|
#[strum(serialize_all = "snake_case")]
|
||||||
enum Testcase {
|
enum Testcase {
|
||||||
EmptyUnary,
|
EmptyUnary,
|
||||||
CacheableUnary,
|
CacheableUnary,
|
||||||
|
|||||||
@@ -1,19 +1,26 @@
|
|||||||
use clap::{ArgAction, Parser};
|
|
||||||
use interop::server;
|
use interop::server;
|
||||||
use tonic::transport::Server;
|
use tonic::transport::Server;
|
||||||
use tonic::transport::{Identity, ServerTlsConfig};
|
use tonic::transport::{Identity, ServerTlsConfig};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Debug)]
|
||||||
struct Opts {
|
struct Opts {
|
||||||
#[clap(name = "use_tls", long, action = ArgAction::SetTrue)]
|
|
||||||
use_tls: bool,
|
use_tls: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Opts {
|
||||||
|
fn parse() -> Result<Self, pico_args::Error> {
|
||||||
|
let mut pargs = pico_args::Arguments::from_env();
|
||||||
|
Ok(Self {
|
||||||
|
use_tls: pargs.contains("--use_tls"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||||
interop::trace_init();
|
interop::trace_init();
|
||||||
|
|
||||||
let matches = Opts::parse();
|
let matches = Opts::parse()?;
|
||||||
|
|
||||||
let addr = "127.0.0.1:10000".parse().unwrap();
|
let addr = "127.0.0.1:10000".parse().unwrap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user