1use crate::context::Context;
2use reedline_repl_rs::{
3 clap::{Arg, Command},
4 {Repl, Result},
5};
6
7mod connect;
8mod context;
9mod error;
10mod requests;
11
12pub async fn run() -> Result<()> {
13 let mut repl = Repl::new(Context::default())
14 .with_name("AlexDB")
15 .with_version("v0.1.0")
16 .with_description("AlexDB client")
17 .with_banner("Welcome to AlexDB client")
18 .with_command_async(
19 Command::new("append")
20 .arg(Arg::new("key").required(true))
21 .arg(Arg::new("value").required(true))
22 .display_order(1)
23 .about("Append value"),
24 |args, context| Box::pin(requests::values::append(args, context)),
25 )
26 .with_command_async(
27 Command::new("connect")
28 .arg(Arg::new("address").required(true))
29 .arg(Arg::new("api_key").required(false))
30 .display_order(2)
31 .about("Connect to database server"),
32 |args, context| Box::pin(connect::connect(args, context)),
33 )
34 .with_command_async(
35 Command::new("create")
36 .arg(Arg::new("key").required(true))
37 .arg(Arg::new("value").required(true))
38 .arg(Arg::new("ttl").required(false))
39 .display_order(3)
40 .about("Create value"),
41 |args, context| Box::pin(requests::values::create(args, context)),
42 )
43 .with_command_async(
44 Command::new("decrement")
45 .arg(Arg::new("key").required(true))
46 .arg(Arg::new("decrement").required(false))
47 .display_order(4)
48 .about("Decrement value"),
49 |args, context| Box::pin(requests::values::decrement(args, context)),
50 )
51 .with_command_async(
52 Command::new("delete")
53 .arg(Arg::new("key").required(true))
54 .display_order(5)
55 .about("Delete value"),
56 |args, context| Box::pin(requests::values::delete(args, context)),
57 )
58 .with_command_async(
59 Command::new("increment")
60 .arg(Arg::new("key").required(true))
61 .arg(Arg::new("increment").required(false))
62 .display_order(6)
63 .about("Increment value"),
64 |args, context| Box::pin(requests::values::increment(args, context)),
65 )
66 .with_command_async(
67 Command::new("list").display_order(7).about("List values"),
68 |args, context| Box::pin(requests::values::list(args, context)),
69 )
70 .with_command_async(
71 Command::new("pop_back")
72 .arg(Arg::new("key").required(true))
73 .arg(Arg::new("pop_back").required(false))
74 .display_order(8)
75 .about("Pop back value"),
76 |args, context| Box::pin(requests::values::pop_back(args, context)),
77 )
78 .with_command_async(
79 Command::new("pop_front")
80 .arg(Arg::new("key").required(true))
81 .arg(Arg::new("pop_front").required(false))
82 .display_order(9)
83 .about("Pop front value"),
84 |args, context| Box::pin(requests::values::pop_front(args, context)),
85 )
86 .with_command_async(
87 Command::new("prepend")
88 .arg(Arg::new("key").required(true))
89 .arg(Arg::new("value").required(true))
90 .display_order(10)
91 .about("Prepend value"),
92 |args, context| Box::pin(requests::values::prepend(args, context)),
93 )
94 .with_command_async(
95 Command::new("read")
96 .arg(Arg::new("key").required(true))
97 .display_order(11)
98 .about("Read value"),
99 |args, context| Box::pin(requests::values::read(args, context)),
100 )
101 .with_command_async(
102 Command::new("update")
103 .arg(Arg::new("key").required(true))
104 .arg(Arg::new("value").required(true))
105 .arg(Arg::new("ttl").required(false))
106 .display_order(12)
107 .about("Update value"),
108 |args, context| Box::pin(requests::values::update(args, context)),
109 );
110
111 repl.run_async().await
112}