Files
empidee/src/commands/reflection/config.rs

51 lines
1.3 KiB
Rust

use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, CommandResponse, ResponseParserError, empty_command_request},
response_tokenizer::{ResponseAttributes, get_and_parse_property, get_property},
};
pub struct Config;
empty_command_request!(Config, "config");
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ConfigResponse {
pub music_directory: String,
pub playlist_directory: String,
pub pcre: bool,
}
impl CommandResponse<'_> for ConfigResponse {
fn into_response_enum(self) -> crate::Response {
todo!()
}
fn from_response_enum(response: crate::Response) -> Option<Self> {
todo!()
}
fn parse(parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError> {
let parts: HashMap<_, _> = parts.into_map()?;
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,
})
}
}
impl Command<'_, '_> for Config {
type Request = ConfigRequest;
type Response = ConfigResponse;
}