chore(interop): Use pico-args instead of clap (#1242)

This commit is contained in:
tottoto
2023-02-07 09:45:32 -05:00
committed by GitHub
parent 09c13fac90
commit 2e3e9acf7b
3 changed files with 30 additions and 21 deletions
+2 -2
View File
@@ -16,8 +16,8 @@ path = "src/bin/server.rs"
[dependencies]
async-stream = "0.3"
clap = {version = ">=4.0.26, <4.1", features = ["derive"]}
clap_lex = "=0.3.0" # keeps msrv to 1.60
strum = {version = "0.24", features = ["derive"]}
pico-args = {version = "0.5", features = ["eq-separator"]}
console = "0.15"
futures-core = "0.3"
futures-util = "0.3"
+17 -15
View File
@@ -1,29 +1,31 @@
use clap::{ArgAction, Parser};
use interop::client;
use std::time::Duration;
use std::{str::FromStr, time::Duration};
use tonic::transport::Endpoint;
use tonic::transport::{Certificate, ClientTlsConfig};
#[derive(Parser)]
#[derive(Debug)]
struct Opts {
#[clap(name = "use_tls", long, action = ArgAction::SetTrue)]
use_tls: bool,
#[arg(
long = "test_case",
use_value_delimiter = true,
num_args(1..),
value_enum,
action = ArgAction::Append
)]
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]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
interop::trace_init();
let matches = Opts::parse();
let matches = Opts::parse()?;
let test_cases = matches.test_case;
@@ -99,8 +101,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
#[derive(Debug, Copy, Clone, clap::ValueEnum)]
#[clap(rename_all = "snake_case")]
#[derive(Debug, strum::EnumString)]
#[strum(serialize_all = "snake_case")]
enum Testcase {
EmptyUnary,
CacheableUnary,
+11 -4
View File
@@ -1,19 +1,26 @@
use clap::{ArgAction, Parser};
use interop::server;
use tonic::transport::Server;
use tonic::transport::{Identity, ServerTlsConfig};
#[derive(Parser)]
#[derive(Debug)]
struct Opts {
#[clap(name = "use_tls", long, action = ArgAction::SetTrue)]
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]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
interop::trace_init();
let matches = Opts::parse();
let matches = Opts::parse()?;
let addr = "127.0.0.1:10000".parse().unwrap();