Skip to content

Replace structopt with its successor, clap 3 #1287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hdrhistogram = { version = "7.2", default-features = false }
quinn = { path = "../quinn" }
rcgen = "0.9.1"
rustls = { version = "0.20", default-features = false, features = ["quic"] }
structopt = "0.3"
clap = { version = "3.2", features = ["derive"] }
tokio = { version = "1.0.1", features = ["rt", "sync"] }
tracing = "0.1.10"
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["env-filter", "fmt", "ansi", "time", "local-time"] }
4 changes: 2 additions & 2 deletions bench/src/bin/bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use anyhow::{Context, Result};
use structopt::StructOpt;
use clap::Parser;
use tokio::sync::Semaphore;
use tracing::{info, trace};

Expand All @@ -17,7 +17,7 @@ use bench::{
};

fn main() {
let opt = Opt::from_args();
let opt = Opt::parse();
configure_tracing_subscriber();

let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).unwrap();
Expand Down
22 changes: 11 additions & 11 deletions bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::{

use anyhow::{Context, Result};
use bytes::Bytes;
use clap::Parser;
use rustls::RootCertStore;
use structopt::StructOpt;
use tokio::runtime::{Builder, Runtime};
use tracing::trace;

Expand Down Expand Up @@ -147,40 +147,40 @@ pub fn transport_config(opt: &Opt) -> quinn::TransportConfig {
config
}

#[derive(StructOpt, Debug, Clone, Copy)]
#[structopt(name = "bulk")]
#[derive(Parser, Debug, Clone, Copy)]
#[clap(name = "bulk")]
pub struct Opt {
/// The total number of clients which should be created
#[structopt(long = "clients", short = "c", default_value = "1")]
#[clap(long = "clients", short = 'c', default_value = "1")]
pub clients: usize,
/// The total number of streams which should be created
#[structopt(long = "streams", short = "n", default_value = "1")]
#[clap(long = "streams", short = 'n', default_value = "1")]
pub streams: usize,
/// The amount of concurrent streams which should be used
#[structopt(long = "max_streams", short = "m", default_value = "1")]
#[clap(long = "max_streams", short = 'm', default_value = "1")]
pub max_streams: usize,
/// Number of bytes to transmit from server to client
///
/// This can use SI prefixes for sizes. E.g. 1M will transfer 1MiB, 10GiB
/// will transfer 10GiB.
#[structopt(long, default_value = "1G", parse(try_from_str = parse_byte_size))]
#[clap(long, default_value = "1G", parse(try_from_str = parse_byte_size))]
pub download_size: u64,
/// Number of bytes to transmit from client to server
///
/// This can use SI prefixes for sizes. E.g. 1M will transfer 1MiB, 10GiB
/// will transfer 10GiB.
#[structopt(long, default_value = "0", parse(try_from_str = parse_byte_size))]
#[clap(long, default_value = "0", parse(try_from_str = parse_byte_size))]
pub upload_size: u64,
/// Show connection stats the at the end of the benchmark
#[structopt(long = "stats")]
#[clap(long = "stats")]
pub stats: bool,
/// Whether to use the unordered read API
#[structopt(long = "unordered")]
#[clap(long = "unordered")]
pub read_unordered: bool,
/// Allows to configure the desired cipher suite
///
/// Valid options are: aes128, aes256, chacha20
#[structopt(long = "cipher", default_value = "aes128")]
#[clap(long = "cipher", default_value = "aes128")]
pub cipher: CipherSuite,
}

Expand Down
2 changes: 1 addition & 1 deletion perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
socket2 = "0.4"
webpki = "0.22"
structopt = "0.3"
clap = { version = "3.2", features = ["derive"] }
tokio = { version = "1.0.1", features = ["rt", "macros", "signal", "net", "sync"] }
tracing = "0.1.10"
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["env-filter", "fmt", "ansi", "time", "local-time"] }
Expand Down
34 changes: 17 additions & 17 deletions perf/src/bin/perf_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use anyhow::{Context, Result};
use bytes::Bytes;
use structopt::StructOpt;
use clap::Parser;
use tokio::sync::Semaphore;
use tracing::{debug, error, info};

Expand All @@ -16,54 +16,54 @@ use perf::stats::{OpenStreamStats, Stats};
use std::path::PathBuf;

/// Connects to a QUIC perf server and maintains a specified pattern of requests until interrupted
#[derive(StructOpt)]
#[structopt(name = "client")]
#[derive(Parser)]
#[clap(name = "client")]
struct Opt {
/// Host to connect to
#[structopt(default_value = "localhost:4433")]
#[clap(default_value = "localhost:4433")]
host: String,
/// Override DNS resolution for host
#[structopt(long)]
#[clap(long)]
ip: Option<IpAddr>,
/// Number of unidirectional requests to maintain concurrently
#[structopt(long, default_value = "0")]
#[clap(long, default_value = "0")]
uni_requests: u64,
/// Number of bidirectional requests to maintain concurrently
#[structopt(long, default_value = "1")]
#[clap(long, default_value = "1")]
bi_requests: u64,
/// Number of bytes to request
#[structopt(long, default_value = "1048576")]
#[clap(long, default_value = "1048576")]
download_size: u64,
/// Number of bytes to transmit, in addition to the request header
#[structopt(long, default_value = "1048576")]
#[clap(long, default_value = "1048576")]
upload_size: u64,
/// The time to run in seconds
#[structopt(long, default_value = "60")]
#[clap(long, default_value = "60")]
duration: u64,
/// The interval in seconds at which stats are reported
#[structopt(long, default_value = "1")]
#[clap(long, default_value = "1")]
interval: u64,
/// Send buffer size in bytes
#[structopt(long, default_value = "2097152")]
#[clap(long, default_value = "2097152")]
send_buffer_size: usize,
/// Receive buffer size in bytes
#[structopt(long, default_value = "2097152")]
#[clap(long, default_value = "2097152")]
recv_buffer_size: usize,
/// Specify the local socket address
#[structopt(long)]
#[clap(long)]
local_addr: Option<SocketAddr>,
/// Whether to print connection statistics
#[structopt(long)]
#[clap(long)]
conn_stats: bool,
/// File path to output JSON statistics to. If the file is '-', stdout will be used
#[cfg(feature = "json-output")]
#[structopt(long)]
#[clap(long)]
json: Option<PathBuf>,
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
let opt = Opt::from_args();
let opt = Opt::parse();

tracing_subscriber::fmt::init();

Expand Down
20 changes: 10 additions & 10 deletions perf/src/bin/perf_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ use std::{fs, net::SocketAddr, path::PathBuf, sync::Arc, time::Duration};

use anyhow::{Context, Result};
use bytes::Bytes;
use structopt::StructOpt;
use clap::Parser;
use tracing::{debug, error, info};

use perf::bind_socket;

#[derive(StructOpt)]
#[structopt(name = "server")]
#[derive(Parser)]
#[clap(name = "server")]
struct Opt {
/// Address to listen on
#[structopt(long = "listen", default_value = "[::]:4433")]
#[clap(long = "listen", default_value = "[::]:4433")]
listen: SocketAddr,
/// TLS private key in PEM format
#[structopt(parse(from_os_str), short = "k", long = "key", requires = "cert")]
#[clap(parse(from_os_str), short = 'k', long = "key", requires = "cert")]
key: Option<PathBuf>,
/// TLS certificate in PEM format
#[structopt(parse(from_os_str), short = "c", long = "cert", requires = "key")]
#[clap(parse(from_os_str), short = 'c', long = "cert", requires = "key")]
cert: Option<PathBuf>,
/// Send buffer size in bytes
#[structopt(long, default_value = "2097152")]
#[clap(long, default_value = "2097152")]
send_buffer_size: usize,
/// Receive buffer size in bytes
#[structopt(long, default_value = "2097152")]
#[clap(long, default_value = "2097152")]
recv_buffer_size: usize,
/// Whether to print connection statistics
#[structopt(long)]
#[clap(long)]
conn_stats: bool,
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
let opt = Opt::from_args();
let opt = Opt::parse();

tracing_subscriber::fmt::init();

Expand Down
2 changes: 1 addition & 1 deletion quinn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ directories-next = "2"
rand = "0.8"
rcgen = "0.9.1"
rustls-pemfile = "1.0.0"
structopt = "0.3.0"
clap = { version = "3.2", features = ["derive"] }
tokio = { version = "1.0.1", features = ["rt", "rt-multi-thread", "time", "macros", "sync"] }
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["env-filter", "fmt", "ansi", "time", "local-time"] }
tracing-futures = { version = "0.2.0", default-features = false, features = ["std-future"] }
Expand Down
16 changes: 8 additions & 8 deletions quinn/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ use std::{
};

use anyhow::{anyhow, Result};
use structopt::StructOpt;
use clap::Parser;
use tracing::{error, info};
use url::Url;

mod common;

/// HTTP/0.9 over QUIC client
#[derive(StructOpt, Debug)]
#[structopt(name = "client")]
#[derive(Parser, Debug)]
#[clap(name = "client")]
struct Opt {
/// Perform NSS-compatible TLS key logging to the file specified in `SSLKEYLOGFILE`.
#[structopt(long = "keylog")]
#[clap(long = "keylog")]
keylog: bool,

url: Url,

/// Override hostname used for certificate verification
#[structopt(long = "host")]
#[clap(long = "host")]
host: Option<String>,

/// Custom certificate authority to trust, in DER format
#[structopt(parse(from_os_str), long = "ca")]
#[clap(parse(from_os_str), long = "ca")]
ca: Option<PathBuf>,

/// Simulate NAT rebinding after connecting
#[structopt(long = "rebind")]
#[clap(long = "rebind")]
rebind: bool,
}

Expand All @@ -48,7 +48,7 @@ fn main() {
.finish(),
)
.unwrap();
let opt = Opt::from_args();
let opt = Opt::parse();
let code = {
if let Err(e) = run(opt) {
eprintln!("ERROR: {}", e);
Expand Down
20 changes: 10 additions & 10 deletions quinn/examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ use std::{
};

use anyhow::{anyhow, bail, Context, Result};
use structopt::{self, StructOpt};
use clap::Parser;
use tracing::{error, info, info_span};
use tracing_futures::Instrument as _;

mod common;

#[derive(StructOpt, Debug)]
#[structopt(name = "server")]
#[derive(Parser, Debug)]
#[clap(name = "server")]
struct Opt {
/// file to log TLS keys to for debugging
#[structopt(long = "keylog")]
#[clap(long = "keylog")]
keylog: bool,
/// directory to serve files from
#[structopt(parse(from_os_str))]
#[clap(parse(from_os_str))]
root: PathBuf,
/// TLS private key in PEM format
#[structopt(parse(from_os_str), short = "k", long = "key", requires = "cert")]
#[clap(parse(from_os_str), short = 'k', long = "key", requires = "cert")]
key: Option<PathBuf>,
/// TLS certificate in PEM format
#[structopt(parse(from_os_str), short = "c", long = "cert", requires = "key")]
#[clap(parse(from_os_str), short = 'c', long = "cert", requires = "key")]
cert: Option<PathBuf>,
/// Enable stateless retries
#[structopt(long = "stateless-retry")]
#[clap(long = "stateless-retry")]
stateless_retry: bool,
/// Address to listen on
#[structopt(long = "listen", default_value = "[::1]:4433")]
#[clap(long = "listen", default_value = "[::1]:4433")]
listen: SocketAddr,
}

Expand All @@ -47,7 +47,7 @@ fn main() {
.finish(),
)
.unwrap();
let opt = Opt::from_args();
let opt = Opt::parse();
let code = {
if let Err(e) = run(opt) {
eprintln!("ERROR: {}", e);
Expand Down