1use clap::{Parser, Subcommand};
6
7#[derive(Parser, Debug)]
11#[command(name = "cache-client")]
12#[command(author, version, about, long_about = None)]
13pub struct Cli {
14 #[clap(subcommand)]
16 pub command: ClientCommand,
17}
18
19#[derive(Subcommand, Debug)]
21pub enum ClientCommand {
22 Get {
27 key: String,
29 },
30
31 Set {
36 key: String,
38 value: String,
40 },
41
42 Delete {
46 key: String,
48 },
49
50 Ping,
54
55 Stats,
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_parse_get() {
67 let cli = Cli::parse_from(["test", "get", "mykey"]);
68 match cli.command {
69 ClientCommand::Get { key } => assert_eq!(key, "mykey"),
70 _ => panic!("Expected Get command"),
71 }
72 }
73
74 #[test]
75 fn test_parse_set() {
76 let cli = Cli::parse_from(["test", "set", "mykey", "myvalue"]);
77 match cli.command {
78 ClientCommand::Set { key, value } => {
79 assert_eq!(key, "mykey");
80 assert_eq!(value, "myvalue");
81 }
82 _ => panic!("Expected Set command"),
83 }
84 }
85
86 #[test]
87 fn test_parse_delete() {
88 let cli = Cli::parse_from(["test", "delete", "mykey"]);
89 match cli.command {
90 ClientCommand::Delete { key } => assert_eq!(key, "mykey"),
91 _ => panic!("Expected Delete command"),
92 }
93 }
94
95 #[test]
96 fn test_parse_ping() {
97 let cli = Cli::parse_from(["test", "ping"]);
98 assert!(matches!(cli.command, ClientCommand::Ping));
99 }
100
101 #[test]
102 fn test_parse_stats() {
103 let cli = Cli::parse_from(["test", "stats"]);
104 assert!(matches!(cli.command, ClientCommand::Stats));
105 }
106}