1
1
use mini_redis:: { client, DEFAULT_PORT } ;
2
2
3
3
use bytes:: Bytes ;
4
+ use clap:: { Parser , Subcommand } ;
4
5
use std:: num:: ParseIntError ;
5
6
use std:: str;
6
7
use std:: time:: Duration ;
7
- use structopt:: StructOpt ;
8
8
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
+ ) ]
11
16
struct Cli {
12
- #[ structopt ( subcommand) ]
17
+ #[ clap ( subcommand) ]
13
18
command : Command ,
14
19
15
- #[ structopt ( name = "hostname" , long = "--host" , default_value = "127.0.0.1" ) ]
20
+ #[ clap ( name = "hostname" , long, default_value = "127.0.0.1" ) ]
16
21
host : String ,
17
22
18
- #[ structopt ( name = "port" , long = "--port" , default_value = DEFAULT_PORT ) ]
19
- port : String ,
23
+ #[ clap ( long, default_value_t = DEFAULT_PORT ) ]
24
+ port : u16 ,
20
25
}
21
26
22
- #[ derive( StructOpt , Debug ) ]
27
+ #[ derive( Subcommand , Debug ) ]
23
28
enum Command {
24
29
/// Get the value of key.
25
30
Get {
@@ -32,19 +37,19 @@ enum Command {
32
37
key : String ,
33
38
34
39
/// Value to set.
35
- #[ structopt ( parse( from_str = bytes_from_str) ) ]
40
+ #[ clap ( parse( from_str = bytes_from_str) ) ]
36
41
value : Bytes ,
37
42
38
43
/// 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) ) ]
40
45
expires : Option < Duration > ,
41
46
} ,
42
47
/// Publisher to send a message to a specific channel.
43
48
Publish {
44
49
/// Name of channel
45
50
channel : String ,
46
51
47
- #[ structopt ( parse( from_str = bytes_from_str) ) ]
52
+ #[ clap ( parse( from_str = bytes_from_str) ) ]
48
53
/// Message to publish
49
54
message : Bytes ,
50
55
} ,
@@ -70,7 +75,7 @@ async fn main() -> mini_redis::Result<()> {
70
75
tracing_subscriber:: fmt:: try_init ( ) ?;
71
76
72
77
// Parse command line arguments
73
- let cli = Cli :: from_args ( ) ;
78
+ let cli = Cli :: parse ( ) ;
74
79
75
80
// Get the remote address to connect to
76
81
let addr = format ! ( "{}:{}" , cli. host, cli. port) ;
0 commit comments