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

View File

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