1
use std::collections::HashMap;
2

            
3
use crate::commands::{
4
    Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
5
    get_and_parse_property, get_property,
6
};
7

            
8
pub struct Config;
9

            
10
pub struct ConfigResponse {
11
    pub music_directory: String,
12
    pub playlist_directory: String,
13
    pub pcre: bool,
14
}
15

            
16
impl Command for Config {
17
    type Response = ConfigResponse;
18
    const COMMAND: &'static str = "config";
19

            
20
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
21
        debug_assert!(parts.next().is_none());
22
        Ok((Request::Config, ""))
23
    }
24

            
25
    fn parse_response(
26
        parts: ResponseAttributes<'_>,
27
    ) -> Result<Self::Response, ResponseParserError> {
28
        let parts: HashMap<_, _> = parts.into();
29

            
30
        let music_directory = get_property!(parts, "music_directory", Text).to_string();
31
        let playlist_directory = get_property!(parts, "playlist_directory", Text).to_string();
32

            
33
        // TODO: is this parsed correctly?
34
        let pcre = get_and_parse_property!(parts, "pcre", Text);
35

            
36
        Ok(ConfigResponse {
37
            music_directory,
38
            playlist_directory,
39
            pcre,
40
        })
41
    }
42
}