Files
empidee/src/commands/reflection/config.rs
T
oysteikt cf09865b02 commands: remove toplevel Request/Response enums
This also exposes all the command types as public API
2026-06-21 14:41:56 +09:00

53 lines
1.4 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 ConfigResponse {
pub fn new(music_directory: String, playlist_directory: String, pcre: bool) -> Self {
ConfigResponse {
music_directory,
playlist_directory,
pcre,
}
}
}
impl CommandResponse for ConfigResponse {
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;
}