diff --git a/.bleep b/.bleep index 6c17b816e..2f3d413c4 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -9c7360a83cbcc28571af2c58f57113750ac1bcf9 \ No newline at end of file +4fac032747f22ebdfbd045342659a5d7086559d7 \ No newline at end of file diff --git a/pingora-core/Cargo.toml b/pingora-core/Cargo.toml index ff12f76b1..586b86fcb 100644 --- a/pingora-core/Cargo.toml +++ b/pingora-core/Cargo.toml @@ -36,7 +36,7 @@ log = { workspace = true } h2 = { workspace = true } lru = { workspace = true } nix = "~0.24.3" -structopt = "0.3" +clap = { version = "4.4.18", features = ["derive"] } once_cell = { workspace = true } serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.8" diff --git a/pingora-core/src/server/configuration/mod.rs b/pingora-core/src/server/configuration/mod.rs index b556cc72d..2def07270 100644 --- a/pingora-core/src/server/configuration/mod.rs +++ b/pingora-core/src/server/configuration/mod.rs @@ -19,11 +19,11 @@ //! * Number of threads per service //! * Error log file path +use clap::Parser; use log::{debug, trace}; use pingora_error::{Error, ErrorType::*, OrErr, Result}; use serde::{Deserialize, Serialize}; use std::fs; -use structopt::StructOpt; /// The configuration file /// @@ -118,22 +118,22 @@ impl Default for ServerConf { /// Command-line options /// /// Call `Opt::from_args()` to build this object from the process's command line arguments. -#[derive(StructOpt, Debug)] -#[structopt(name = "basic")] +#[derive(Parser, Debug)] +#[clap(name = "basic")] pub struct Opt { /// Whether this server should try to upgrade from a running old server /// /// `-u` or `--upgrade` can be used - #[structopt(short, long)] + #[clap(short, long)] pub upgrade: bool, /// Whether should run this server in the background /// /// `-d` or `--daemon` can be used - #[structopt(short, long)] + #[clap(short, long)] pub daemon: bool, /// Not actually used. This flag is there so that the server is not upset seeing this flag /// passed from `cargo test` sometimes - #[structopt(long)] + #[clap(long)] pub nocapture: bool, /// Test the configuration and exit /// @@ -143,23 +143,23 @@ pub struct Opt { /// service can start before shutting down the old server process. /// /// `-t` or `--test` can be used - #[structopt(short, long)] + #[clap(short, long)] pub test: bool, /// The path to the configuration file. /// /// See [`ServerConf`] for more details of the configuration file. /// /// `-c` or `--conf` can be used - #[structopt(short, long)] + #[clap(short, long)] pub conf: Option, } /// Create the default instance of Opt based on the current command-line args. -/// This is equivalent to running `Opt::from_args` but does not require the -/// caller to have included the `structopt::StructOpt` +/// This is equivalent to running `Opt::parse` but does not require the +/// caller to have included the `clap::Parser` impl Default for Opt { fn default() -> Self { - Opt::from_args() + Opt::parse() } } diff --git a/pingora-core/tests/utils/mod.rs b/pingora-core/tests/utils/mod.rs index 1555b7dbc..af5de8544 100644 --- a/pingora-core/tests/utils/mod.rs +++ b/pingora-core/tests/utils/mod.rs @@ -15,11 +15,11 @@ use once_cell::sync::Lazy; use std::{thread, time}; +use clap::Parser; use pingora_core::listeners::Listeners; use pingora_core::server::configuration::Opt; use pingora_core::server::Server; use pingora_core::services::listening::Service; -use structopt::StructOpt; use async_trait::async_trait; use bytes::Bytes; @@ -106,7 +106,7 @@ impl MyServer { "tests/pingora_conf.yaml".into(), ]; let server_handle = thread::spawn(|| { - entry_point(Some(Opt::from_iter(opts))); + entry_point(Some(Opt::parse_from(opts))); }); // wait until the server is up thread::sleep(time::Duration::from_secs(2)); diff --git a/pingora-proxy/Cargo.toml b/pingora-proxy/Cargo.toml index c39119612..29b7ec265 100644 --- a/pingora-proxy/Cargo.toml +++ b/pingora-proxy/Cargo.toml @@ -31,7 +31,7 @@ async-trait = { workspace = true } log = { workspace = true } h2 = { workspace = true } once_cell = { workspace = true } -structopt = "0.3" +clap = { version = "4.4.18", features = ["derive"] } regex = "1" [dev-dependencies] diff --git a/pingora-proxy/examples/ctx.rs b/pingora-proxy/examples/ctx.rs index 36169e21a..4838391e3 100644 --- a/pingora-proxy/examples/ctx.rs +++ b/pingora-proxy/examples/ctx.rs @@ -13,9 +13,9 @@ // limitations under the License. use async_trait::async_trait; +use clap::Parser; use log::info; use std::sync::Mutex; -use structopt::StructOpt; use pingora_core::server::configuration::Opt; use pingora_core::server::Server; @@ -82,7 +82,7 @@ fn main() { env_logger::init(); // read command line arguments - let opt = Opt::from_args(); + let opt = Opt::parse(); let mut my_server = Server::new(Some(opt)).unwrap(); my_server.bootstrap(); diff --git a/pingora-proxy/examples/gateway.rs b/pingora-proxy/examples/gateway.rs index 27c502049..0bd53306d 100644 --- a/pingora-proxy/examples/gateway.rs +++ b/pingora-proxy/examples/gateway.rs @@ -13,9 +13,9 @@ // limitations under the License. use async_trait::async_trait; +use clap::Parser; use log::info; use prometheus::register_int_counter; -use structopt::StructOpt; use pingora_core::server::configuration::Opt; use pingora_core::server::Server; @@ -114,7 +114,7 @@ fn main() { env_logger::init(); // read command line arguments - let opt = Opt::from_args(); + let opt = Opt::parse(); let mut my_server = Server::new(Some(opt)).unwrap(); my_server.bootstrap(); diff --git a/pingora-proxy/examples/load_balancer.rs b/pingora-proxy/examples/load_balancer.rs index 425b6ece5..614981d60 100644 --- a/pingora-proxy/examples/load_balancer.rs +++ b/pingora-proxy/examples/load_balancer.rs @@ -13,10 +13,10 @@ // limitations under the License. use async_trait::async_trait; +use clap::Parser; use log::info; use pingora_core::services::background::background_service; use std::{sync::Arc, time::Duration}; -use structopt::StructOpt; use pingora_core::server::configuration::Opt; use pingora_core::server::Server; @@ -62,7 +62,7 @@ fn main() { env_logger::init(); // read command line arguments - let opt = Opt::from_args(); + let opt = Opt::parse(); let mut my_server = Server::new(Some(opt)).unwrap(); my_server.bootstrap(); diff --git a/pingora-proxy/examples/modify_response.rs b/pingora-proxy/examples/modify_response.rs index 5166dc64b..6730f7186 100644 --- a/pingora-proxy/examples/modify_response.rs +++ b/pingora-proxy/examples/modify_response.rs @@ -14,9 +14,9 @@ use async_trait::async_trait; use bytes::Bytes; +use clap::Parser; use serde::{Deserialize, Serialize}; use std::net::ToSocketAddrs; -use structopt::StructOpt; use pingora_core::server::configuration::Opt; use pingora_core::server::Server; @@ -117,7 +117,7 @@ impl ProxyHttp for Json2Yaml { fn main() { env_logger::init(); - let opt = Opt::from_args(); + let opt = Opt::parse(); let mut my_server = Server::new(Some(opt)).unwrap(); my_server.bootstrap(); diff --git a/pingora-proxy/tests/utils/server_utils.rs b/pingora-proxy/tests/utils/server_utils.rs index e6ffe5834..02034fe31 100644 --- a/pingora-proxy/tests/utils/server_utils.rs +++ b/pingora-proxy/tests/utils/server_utils.rs @@ -14,6 +14,7 @@ use super::cert; use async_trait::async_trait; +use clap::Parser; use http::header::VARY; use http::HeaderValue; use once_cell::sync::Lazy; @@ -36,7 +37,6 @@ use pingora_proxy::{ProxyHttp, Session}; use std::collections::{HashMap, HashSet}; use std::sync::Arc; use std::thread; -use structopt::StructOpt; pub struct ExampleProxyHttps {} @@ -469,7 +469,7 @@ fn test_main() { "-c".into(), "tests/pingora_conf.yaml".into(), ]; - let mut my_server = pingora_core::server::Server::new(Some(Opt::from_iter(opts))).unwrap(); + let mut my_server = pingora_core::server::Server::new(Some(Opt::parse_from(opts))).unwrap(); my_server.bootstrap(); let mut proxy_service_http = diff --git a/pingora/Cargo.toml b/pingora/Cargo.toml index 8ae3aba5a..118a0a73b 100644 --- a/pingora/Cargo.toml +++ b/pingora/Cargo.toml @@ -30,7 +30,7 @@ pingora-proxy = { version = "0.2.0", path = "../pingora-proxy", optional = true, pingora-cache = { version = "0.2.0", path = "../pingora-cache", optional = true, default-features = false } [dev-dependencies] -structopt = "0.3" +clap = { version = "4.4.18", features = ["derive"] } tokio = { workspace = true, features = ["rt-multi-thread", "signal"] } matches = "0.1" env_logger = "0.9" diff --git a/pingora/examples/server.rs b/pingora/examples/server.rs index 5b6219366..a2a092e9d 100644 --- a/pingora/examples/server.rs +++ b/pingora/examples/server.rs @@ -22,7 +22,7 @@ use pingora::services::background::{background_service, BackgroundService}; use pingora::services::{listening::Service as ListeningService, Service}; use async_trait::async_trait; -use structopt::StructOpt; +use clap::Parser; use tokio::time::interval; use std::time::Duration; @@ -106,7 +106,7 @@ pub fn main() { print!("{USAGE}"); - let opt = Some(Opt::from_args()); + let opt = Some(Opt::parse()); let mut my_server = Server::new(opt).unwrap(); my_server.bootstrap();