-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement info cmd and print error for unrecognized cmd
- Loading branch information
Showing
4 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::{Backend, CommandError, CommandExecutor, RespArray, RespFrame}; | ||
|
||
use super::validate_command; | ||
|
||
#[derive(Debug)] | ||
pub struct Info(); | ||
|
||
impl CommandExecutor for Info { | ||
fn execute(self, _: &Backend) -> RespFrame { | ||
"Ok".into() | ||
} | ||
} | ||
|
||
impl Info { | ||
pub fn new() -> Self { | ||
Self() | ||
} | ||
} | ||
|
||
impl Default for Info { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl TryFrom<RespArray> for Info { | ||
type Error = CommandError; | ||
fn try_from(value: RespArray) -> Result<Self, Self::Error> { | ||
validate_command(&value, &["info"], 0, super::ArgsCheckRule::Equal)?; | ||
|
||
Ok(Info::new()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
use crate::{Backend, CommandExecutor, RespFrame}; | ||
use crate::{Backend, BulkString, CommandExecutor, RespFrame, SimpleError}; | ||
|
||
#[derive(Debug)] | ||
pub struct Unrecognized; | ||
pub struct Unrecognized(pub(crate) BulkString); | ||
|
||
impl CommandExecutor for Unrecognized { | ||
fn execute(self, _: &Backend) -> RespFrame { | ||
"OK".into() | ||
SimpleError::new(format!( | ||
"ERR unknown command '{}', with args beginning with:", | ||
self.0 | ||
)) | ||
.into() | ||
} | ||
} | ||
|
||
impl Unrecognized { | ||
pub fn new(cmd: BulkString) -> Self { | ||
Self(cmd) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters