43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use crate::commands::{
|
|
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
|
get_and_parse_property, get_property,
|
|
};
|
|
|
|
pub struct Config;
|
|
|
|
pub struct ConfigResponse {
|
|
pub music_directory: String,
|
|
pub playlist_directory: String,
|
|
pub pcre: bool,
|
|
}
|
|
|
|
impl Command for Config {
|
|
type Response = ConfigResponse;
|
|
const COMMAND: &'static str = "config";
|
|
|
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
|
debug_assert!(parts.next().is_none());
|
|
Ok((Request::Config, ""))
|
|
}
|
|
|
|
fn parse_response(
|
|
parts: ResponseAttributes<'_>,
|
|
) -> Result<Self::Response, ResponseParserError> {
|
|
let parts: HashMap<_, _> = parts.into();
|
|
|
|
let music_directory = get_property!(parts, "music_directory", Text).to_string();
|
|
let playlist_directory = get_property!(parts, "playlist_directory", Text).to_string();
|
|
|
|
// TODO: is this parsed correctly?
|
|
let pcre = get_and_parse_property!(parts, "pcre", Text);
|
|
|
|
Ok(ConfigResponse {
|
|
music_directory,
|
|
playlist_directory,
|
|
pcre,
|
|
})
|
|
}
|
|
}
|