11use mini_redis:: { client, DEFAULT_PORT } ;
22
33use bytes:: Bytes ;
4+ use clap:: { Parser , Subcommand } ;
45use std:: num:: ParseIntError ;
56use std:: str;
67use std:: time:: Duration ;
7- use structopt:: StructOpt ;
88
9- #[ derive( StructOpt , Debug ) ]
10- #[ structopt( name = "mini-redis-cli" , version = env!( "CARGO_PKG_VERSION" ) , author = env!( "CARGO_PKG_AUTHORS" ) , about = "Issue Redis commands" ) ]
9+ #[ derive( Parser , Debug ) ]
10+ #[ clap(
11+ name = "mini-redis-cli" ,
12+ version,
13+ author,
14+ about = "Issue Redis commands"
15+ ) ]
1116struct Cli {
12- #[ structopt ( subcommand) ]
17+ #[ clap ( subcommand) ]
1318 command : Command ,
1419
15- #[ structopt ( name = "hostname" , long = "--host" , default_value = "127.0.0.1" ) ]
20+ #[ clap ( name = "hostname" , long, default_value = "127.0.0.1" ) ]
1621 host : String ,
1722
18- #[ structopt ( name = "port" , long = "--port" , default_value = DEFAULT_PORT ) ]
19- port : String ,
23+ #[ clap ( long, default_value_t = DEFAULT_PORT ) ]
24+ port : u16 ,
2025}
2126
22- #[ derive( StructOpt , Debug ) ]
27+ #[ derive( Subcommand , Debug ) ]
2328enum Command {
2429 /// Get the value of key.
2530 Get {
@@ -32,19 +37,19 @@ enum Command {
3237 key : String ,
3338
3439 /// Value to set.
35- #[ structopt ( parse( from_str = bytes_from_str) ) ]
40+ #[ clap ( parse( from_str = bytes_from_str) ) ]
3641 value : Bytes ,
3742
3843 /// Expire the value after specified amount of time
39- #[ structopt ( parse( try_from_str = duration_from_ms_str) ) ]
44+ #[ clap ( parse( try_from_str = duration_from_ms_str) ) ]
4045 expires : Option < Duration > ,
4146 } ,
4247 /// Publisher to send a message to a specific channel.
4348 Publish {
4449 /// Name of channel
4550 channel : String ,
4651
47- #[ structopt ( parse( from_str = bytes_from_str) ) ]
52+ #[ clap ( parse( from_str = bytes_from_str) ) ]
4853 /// Message to publish
4954 message : Bytes ,
5055 } ,
@@ -70,7 +75,7 @@ async fn main() -> mini_redis::Result<()> {
7075 tracing_subscriber:: fmt:: try_init ( ) ?;
7176
7277 // Parse command line arguments
73- let cli = Cli :: from_args ( ) ;
78+ let cli = Cli :: parse ( ) ;
7479
7580 // Get the remote address to connect to
7681 let addr = format ! ( "{}:{}" , cli. host, cli. port) ;
0 commit comments