commands: implement response parser for listmounts

This commit is contained in:
2025-11-21 14:32:06 +09:00
parent 2b1e99445a
commit 7dc3d7f9cf

View File

@@ -1,12 +1,11 @@
use crate::{
Request,
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
commands::{expect_property_type, Command, RequestParserResult, ResponseAttributes, ResponseParserError}, Request
};
pub struct ListMounts;
impl Command for ListMounts {
type Response = Vec<(String, String)>;
type Response = Vec<String>;
const COMMAND: &'static str = "listmounts";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
@@ -17,6 +16,39 @@ impl Command for ListMounts {
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
unimplemented!()
let parts: Vec<_> = parts.into();
let mut result = Vec::with_capacity(parts.len());
for (key, value) in parts.into_iter() {
if key != "mount" {
return Err(ResponseParserError::UnexpectedProperty(key));
}
let value = expect_property_type!(Some(value), "mount", Text).to_string();
result.push(value);
}
Ok(result)
}
}
#[cfg(test)]
mod tests {
use indoc::indoc;
use super::*;
#[test]
fn test_parse_response() {
let input = indoc! {"
mount:
mount: /mnt/music
OK
"};
let result = ListMounts::parse_raw_response(input);
assert_eq!(
result,
Ok(vec![
"".to_string(),
"/mnt/music".to_string(),
])
);
}
}