kade_proto/cmd/
version.rs1use crate::prelude::*;
2use bytes::Bytes;
3use std::env::consts;
4use tracing::{debug, instrument};
5
6#[derive(Debug, Default)]
7pub struct Version {}
8
9impl Version {
10 pub fn new() -> Version { Version {} }
11
12 pub fn parse_frames(parse: &mut Parse) -> crate::Result<Version> {
13 match parse.next_bytes() {
14 Ok(_) => Ok(Version::new()),
15 Err(ParseError::EndOfStream) => Ok(Version::default()),
16 Err(e) => Err(e.into()),
17 }
18 }
19
20 #[instrument(skip(self, dst))]
21 pub async fn apply(self, dst: &mut Connection) -> crate::Result<()> {
22 let msg = format!("v{} {}-{}", env!("CARGO_PKG_VERSION"), consts::OS, consts::ARCH);
23 let response = Frame::Simple(msg);
24
25 debug!(?response);
26 dst.write_frame(&response).await?;
27
28 Ok(())
29 }
30
31 pub fn into_frame(self) -> Frame {
32 let mut frame = Frame::array();
33 frame.push_bulk(Bytes::from("version".as_bytes()));
34 frame
35 }
36}