Skip to content

Commit 4229612

Browse files
guozhihao-224claude
andcommitted
fix(cmd): move INFO test module to end of admin.rs
clippy::items-after-test-module fires because ConfigCmd follows the cfg(test) tests; CI runs clippy --all-targets. Relocate the test module below ConfigCmd. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 4839865 commit 4229612

1 file changed

Lines changed: 87 additions & 87 deletions

File tree

src/cmd/src/admin.rs

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,93 @@ impl Cmd for InfoCmd {
262262
}
263263
}
264264

265+
/// CONFIG command - Get/Set configuration parameters
266+
#[derive(Clone, Default)]
267+
pub struct ConfigCmd {
268+
meta: CmdMeta,
269+
}
270+
271+
impl ConfigCmd {
272+
pub fn new() -> Self {
273+
Self {
274+
meta: CmdMeta {
275+
name: "config".to_string(),
276+
arity: -2,
277+
flags: CmdFlags::ADMIN,
278+
acl_category: AclCategory::ADMIN,
279+
..Default::default()
280+
},
281+
}
282+
}
283+
}
284+
285+
impl Cmd for ConfigCmd {
286+
impl_cmd_meta!();
287+
impl_cmd_clone_box!();
288+
289+
fn do_initial(&self, _client: &Client) -> bool {
290+
true
291+
}
292+
293+
fn do_cmd(&self, client: &Client, _storage: Arc<Storage>) {
294+
if client.argv().len() < 2 {
295+
client.set_reply(RespData::Error(
296+
"ERR wrong number of arguments for 'config' command".into(),
297+
));
298+
return;
299+
}
300+
301+
let subcommand = String::from_utf8_lossy(&client.argv()[1]).to_lowercase();
302+
303+
match subcommand.as_str() {
304+
"get" => {
305+
if client.argv().len() < 3 {
306+
client.set_reply(RespData::Error(
307+
"ERR wrong number of arguments for 'config get' command".into(),
308+
));
309+
return;
310+
}
311+
312+
let parameter = String::from_utf8_lossy(&client.argv()[2]).to_lowercase();
313+
314+
// Return configuration (cluster mode is removed; report disabled)
315+
match parameter.as_str() {
316+
"cluster-enabled" => {
317+
let result = vec![
318+
RespData::BulkString(Some(Bytes::from("cluster-enabled"))),
319+
RespData::BulkString(Some(Bytes::from("no"))),
320+
];
321+
client.set_reply(RespData::Array(Some(result)));
322+
}
323+
"*" => {
324+
let result = vec![
325+
RespData::BulkString(Some(Bytes::from("cluster-enabled"))),
326+
RespData::BulkString(Some(Bytes::from("no"))),
327+
RespData::BulkString(Some(Bytes::from("port"))),
328+
RespData::BulkString(Some(Bytes::from("7379"))),
329+
];
330+
client.set_reply(RespData::Array(Some(result)));
331+
}
332+
_ => {
333+
client.set_reply(RespData::Array(Some(vec![])));
334+
}
335+
}
336+
}
337+
"set" => {
338+
// For now, don't allow runtime configuration changes
339+
client.set_reply(RespData::Error(
340+
"ERR runtime configuration changes not supported".into(),
341+
));
342+
}
343+
_ => {
344+
client.set_reply(RespData::Error(
345+
format!("ERR unknown CONFIG subcommand '{}'", subcommand).into(),
346+
));
347+
}
348+
}
349+
}
350+
}
351+
265352
#[cfg(test)]
266353
mod tests {
267354
use client::{Client, StreamTrait};
@@ -394,90 +481,3 @@ mod tests {
394481
assert!(out.contains("# Vector\r\n"), "{out}");
395482
}
396483
}
397-
398-
/// CONFIG command - Get/Set configuration parameters
399-
#[derive(Clone, Default)]
400-
pub struct ConfigCmd {
401-
meta: CmdMeta,
402-
}
403-
404-
impl ConfigCmd {
405-
pub fn new() -> Self {
406-
Self {
407-
meta: CmdMeta {
408-
name: "config".to_string(),
409-
arity: -2,
410-
flags: CmdFlags::ADMIN,
411-
acl_category: AclCategory::ADMIN,
412-
..Default::default()
413-
},
414-
}
415-
}
416-
}
417-
418-
impl Cmd for ConfigCmd {
419-
impl_cmd_meta!();
420-
impl_cmd_clone_box!();
421-
422-
fn do_initial(&self, _client: &Client) -> bool {
423-
true
424-
}
425-
426-
fn do_cmd(&self, client: &Client, _storage: Arc<Storage>) {
427-
if client.argv().len() < 2 {
428-
client.set_reply(RespData::Error(
429-
"ERR wrong number of arguments for 'config' command".into(),
430-
));
431-
return;
432-
}
433-
434-
let subcommand = String::from_utf8_lossy(&client.argv()[1]).to_lowercase();
435-
436-
match subcommand.as_str() {
437-
"get" => {
438-
if client.argv().len() < 3 {
439-
client.set_reply(RespData::Error(
440-
"ERR wrong number of arguments for 'config get' command".into(),
441-
));
442-
return;
443-
}
444-
445-
let parameter = String::from_utf8_lossy(&client.argv()[2]).to_lowercase();
446-
447-
// Return configuration (cluster mode is removed; report disabled)
448-
match parameter.as_str() {
449-
"cluster-enabled" => {
450-
let result = vec![
451-
RespData::BulkString(Some(Bytes::from("cluster-enabled"))),
452-
RespData::BulkString(Some(Bytes::from("no"))),
453-
];
454-
client.set_reply(RespData::Array(Some(result)));
455-
}
456-
"*" => {
457-
let result = vec![
458-
RespData::BulkString(Some(Bytes::from("cluster-enabled"))),
459-
RespData::BulkString(Some(Bytes::from("no"))),
460-
RespData::BulkString(Some(Bytes::from("port"))),
461-
RespData::BulkString(Some(Bytes::from("7379"))),
462-
];
463-
client.set_reply(RespData::Array(Some(result)));
464-
}
465-
_ => {
466-
client.set_reply(RespData::Array(Some(vec![])));
467-
}
468-
}
469-
}
470-
"set" => {
471-
// For now, don't allow runtime configuration changes
472-
client.set_reply(RespData::Error(
473-
"ERR runtime configuration changes not supported".into(),
474-
));
475-
}
476-
_ => {
477-
client.set_reply(RespData::Error(
478-
format!("ERR unknown CONFIG subcommand '{}'", subcommand).into(),
479-
));
480-
}
481-
}
482-
}
483-
}

0 commit comments

Comments
 (0)