Update to clap 4.2.7 (#125)

This commit is contained in:
tottoto
2023-05-18 19:55:46 +09:00
committed by GitHub
parent df98a941ac
commit fe55e5f5eb
3 changed files with 496 additions and 311 deletions

792
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -25,7 +25,7 @@ async-stream = "0.3.0"
atoi = "2.0.0" atoi = "2.0.0"
bytes = "1" bytes = "1"
rand = "0.8.5" rand = "0.8.5"
clap = { version = "3.1.18", features = ["derive"] } clap = { version = "4.2.7", features = ["derive"] }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1" tokio-stream = "0.1"
tracing = "0.1.34" tracing = "0.1.34"

View File

@@ -2,6 +2,7 @@ use mini_redis::{clients::Client, DEFAULT_PORT};
use bytes::Bytes; use bytes::Bytes;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use std::convert::Infallible;
use std::num::ParseIntError; use std::num::ParseIntError;
use std::str; use std::str;
use std::time::Duration; use std::time::Duration;
@@ -28,7 +29,7 @@ struct Cli {
enum Command { enum Command {
Ping { Ping {
/// Message to ping /// Message to ping
#[clap(parse(from_str = bytes_from_str))] #[clap(value_parser = bytes_from_str)]
msg: Option<Bytes>, msg: Option<Bytes>,
}, },
/// Get the value of key. /// Get the value of key.
@@ -42,11 +43,11 @@ enum Command {
key: String, key: String,
/// Value to set. /// Value to set.
#[clap(parse(from_str = bytes_from_str))] #[clap(value_parser = bytes_from_str)]
value: Bytes, value: Bytes,
/// Expire the value after specified amount of time /// Expire the value after specified amount of time
#[clap(parse(try_from_str = duration_from_ms_str))] #[clap(value_parser = duration_from_ms_str)]
expires: Option<Duration>, expires: Option<Duration>,
}, },
/// Publisher to send a message to a specific channel. /// Publisher to send a message to a specific channel.
@@ -54,7 +55,7 @@ enum Command {
/// Name of channel /// Name of channel
channel: String, channel: String,
#[clap(parse(from_str = bytes_from_str))] #[clap(value_parser = bytes_from_str)]
/// Message to publish /// Message to publish
message: Bytes, message: Bytes,
}, },
@@ -153,6 +154,6 @@ fn duration_from_ms_str(src: &str) -> Result<Duration, ParseIntError> {
Ok(Duration::from_millis(ms)) Ok(Duration::from_millis(ms))
} }
fn bytes_from_str(src: &str) -> Bytes { fn bytes_from_str(src: &str) -> Result<Bytes, Infallible> {
Bytes::from(src.to_string()) Ok(Bytes::from(src.to_string()))
} }