From b172fef4beb8d4f2094d07cb3d995fca578df990 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 21 Nov 2025 14:32:06 +0900 Subject: [PATCH] commands: implement response parser for `listmounts` --- .../mounts_and_neighbors/listmounts.rs | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/commands/mounts_and_neighbors/listmounts.rs b/src/commands/mounts_and_neighbors/listmounts.rs index 91b05c0c..640cac2a 100644 --- a/src/commands/mounts_and_neighbors/listmounts.rs +++ b/src/commands/mounts_and_neighbors/listmounts.rs @@ -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; 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> { - 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(), + ]) + ); } }