use structopt instead of Clap (#41)

mini-redis uses the CLI derive pattern. Clap does not yet have a release
supporting this pattern. Using structopt allows mini-redis to avoid git
dependencies.
This commit is contained in:
Carl Lerche
2020-05-12 16:48:16 -07:00
committed by GitHub
parent 84f7086238
commit fdba12b964
4 changed files with 430 additions and 458 deletions

View File

@@ -8,7 +8,7 @@
use mini_redis::{server, DEFAULT_PORT};
use clap::Clap;
use structopt::StructOpt;
use tokio::net::TcpListener;
use tokio::signal;
@@ -18,7 +18,7 @@ pub async fn main() -> mini_redis::Result<()> {
// see https://docs.rs/tracing for more info
tracing_subscriber::fmt::try_init()?;
let cli = Cli::parse();
let cli = Cli::from_args();
let port = cli.port.unwrap_or(DEFAULT_PORT.to_string());
// Bind a TCP listener
@@ -27,9 +27,9 @@ pub async fn main() -> mini_redis::Result<()> {
server::run(listener, signal::ctrl_c()).await
}
#[derive(Clap, Debug)]
#[clap(name = "mini-redis-server", version = env!("CARGO_PKG_VERSION"), author = env!("CARGO_PKG_AUTHORS"), about = "A Redis server")]
#[derive(StructOpt, Debug)]
#[structopt(name = "mini-redis-server", version = env!("CARGO_PKG_VERSION"), author = env!("CARGO_PKG_AUTHORS"), about = "A Redis server")]
struct Cli {
#[clap(name = "port", long = "--port")]
#[structopt(name = "port", long = "--port")]
port: Option<String>,
}