Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a46ea0

Browse filesBrowse files
add "show help" command
Signed-off-by: Sebastian Webber <sebastian@swebber.me>
1 parent 3c9565d commit 8a46ea0
Copy full SHA for 8a46ea0

File tree

Expand file treeCollapse file tree

2 files changed

+64
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+64
-1
lines changed

‎src/admin.rs

Copy file name to clipboardExpand all lines: src/admin.rs
+47-1Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::pool::BanReason;
22
use crate::stats::pool::PoolStats;
33
use bytes::{Buf, BufMut, BytesMut};
4-
use log::{error, info, trace};
4+
use log::{debug, error, info, trace};
55
use nix::sys::signal::{self, Signal};
66
use nix::unistd::Pid;
77
use std::collections::HashMap;
@@ -84,6 +84,10 @@ where
8484
shutdown(stream).await
8585
}
8686
"SHOW" => match query_parts[1].to_ascii_uppercase().as_str() {
87+
"HELP" => {
88+
trace!("SHOW HELP");
89+
show_help(stream).await
90+
}
8791
"BANS" => {
8892
trace!("SHOW BANS");
8993
show_bans(stream).await
@@ -271,6 +275,48 @@ where
271275
write_all_half(stream, &res).await
272276
}
273277

278+
/// Show all available options.
279+
async fn show_help<T>(stream: &mut T) -> Result<(), Error>
280+
where
281+
T: tokio::io::AsyncWrite + std::marker::Unpin,
282+
{
283+
let mut res = BytesMut::new();
284+
285+
286+
let detail_msg = vec![
287+
"",
288+
"SHOW HELP|CONFIG|DATABASES|POOLS|CLIENTS|SERVERS|USERS|VERSION",
289+
// "SHOW PEERS|PEER_POOLS", // missing PEERS|PEER_POOLS
290+
// "SHOW FDS|SOCKETS|ACTIVE_SOCKETS|LISTS|MEM|STATE", // missing FDS|SOCKETS|ACTIVE_SOCKETS|MEM|STATE
291+
"SHOW LISTS",
292+
// "SHOW DNS_HOSTS|DNS_ZONES", // missing DNS_HOSTS|DNS_ZONES
293+
"SHOW STATS", // missing STATS_TOTALS|STATS_AVERAGES|TOTALS
294+
"SET key = arg",
295+
"RELOAD",
296+
"PAUSE [<db>, <user>]",
297+
"RESUME [<db>, <user>]",
298+
// "DISABLE <db>", // missing
299+
// "ENABLE <db>", // missing
300+
// "RECONNECT [<db>]", missing
301+
// "KILL <db>",
302+
// "SUSPEND",
303+
"SHUTDOWN",
304+
// "WAIT_CLOSE [<db>]", // missing
305+
];
306+
307+
res.put(notify("Console usage", detail_msg.join("\n\t")));
308+
res.put(command_complete("SHOW"));
309+
310+
// ReadyForQuery
311+
res.put_u8(b'Z');
312+
res.put_i32(5);
313+
res.put_u8(b'I');
314+
315+
debug!("{:?}", res);
316+
317+
write_all_half(stream, &res).await
318+
}
319+
274320
/// Show shards and replicas.
275321
async fn show_databases<T>(stream: &mut T) -> Result<(), Error>
276322
where

‎src/messages.rs

Copy file name to clipboardExpand all lines: src/messages.rs
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,23 @@ pub fn command_complete(command: &str) -> BytesMut {
530530
res
531531
}
532532

533+
/// Create a notify message.
534+
pub fn notify(message: &str, details: String) -> BytesMut {
535+
let mut notify_cmd = BytesMut::new();
536+
537+
notify_cmd.put_slice("SNOTICE\0".as_bytes());
538+
notify_cmd.put_slice("C00000\0".as_bytes());
539+
notify_cmd.put_slice(format!("M{}\0", message).as_bytes());
540+
notify_cmd.put_slice(format!("D{}\0", details).as_bytes());
541+
542+
let mut res = BytesMut::new();
543+
res.put_u8(b'N');
544+
res.put_i32(notify_cmd.len() as i32 + 4);
545+
res.put(notify_cmd);
546+
547+
res
548+
}
549+
533550
pub fn flush() -> BytesMut {
534551
let mut bytes = BytesMut::new();
535552
bytes.put_u8(b'H');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.