Fixes #235 - Replace unmaintained structopt crate by clap

---
Fixed formatting

Includes-commit: 05f9754166
Includes-commit: 29286c7e71
Replicated-from: https://github.com/cloudflare/pingora/pull/239
This commit is contained in:
Wladimir Palant 2024-05-10 18:18:53 +00:00 committed by Edward Wang
parent 6db86b6929
commit 795594db83
12 changed files with 29 additions and 29 deletions

2
.bleep
View file

@ -1 +1 @@
9c7360a83cbcc28571af2c58f57113750ac1bcf9
4fac032747f22ebdfbd045342659a5d7086559d7

View file

@ -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"

View file

@ -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<String>,
}
/// 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()
}
}

View file

@ -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));

View file

@ -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]

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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 =

View file

@ -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"

View file

@ -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();