diff --git a/src/commands/run.rs b/src/commands/run.rs index 6b680f8..8aaf3ad 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,3 +1,5 @@ +use std::io::Read; + use crate::args::Run; fn reshape_audio_data(input: &[T], channels: usize) -> Vec> @@ -28,6 +30,25 @@ where output } -pub fn run(args: Run) { +pub fn run(run: Run) { + let config = std::path::Path::new(&run.config); -} \ No newline at end of file + if !config.exists() { + eprintln!("Config file does not exists."); + return; + } + + let mut buf = String::default(); + let mut config = if let Ok(config) = std::fs::File::open(&config) { + config + } else { + eprintln!("Cannot open config file."); + return; + }; + + config.read_to_string(&mut buf).unwrap(); + + let config: crate::config::Config = serde_yaml::from_str(&buf).unwrap(); + + println!("{:?}", config); +} diff --git a/src/config.rs b/src/config.rs index 099eada..fb3eec5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,52 +1,52 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] -struct RoutesConfig { - routes: Routes, +pub struct Config { + pub routes: Routes, } #[derive(Debug, Serialize, Deserialize)] -struct Routes { - input: Vec, - output: Vec, +pub struct Routes { + pub input: Vec, + pub output: Vec, } #[derive(Debug, Serialize, Deserialize)] -struct Input { - name: String, - virtual_device: String, - device: Device, +pub struct Input { + pub name: String, + pub virtual_device: String, + pub device: Device, } #[derive(Debug, Serialize, Deserialize)] -struct Output { - name: String, - input: OutputInput, - device: Device, +pub struct Output { + pub name: String, + pub input: OutputInput, + pub device: Device, } #[derive(Debug, Serialize, Deserialize)] -struct OutputInput { - virtual_device: String, +pub struct OutputInput { + pub virtual_device: String, } #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] -enum Device { +pub enum Device { Local { local: LocalDevice }, Remote { remote: RemoteDevice }, } #[derive(Debug, Serialize, Deserialize)] -struct LocalDevice { - name: String, +pub struct LocalDevice { + pub name: String, } #[derive(Debug, Serialize, Deserialize)] -struct RemoteDevice { - address: String, - port: u16, - protocol: String, - buffer: usize, - channels: u8, +pub struct RemoteDevice { + pub address: String, + pub port: u16, + pub protocol: String, + pub buffer: usize, + pub channels: u8, }