aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/by-name/mp/mpdpopm/src/config.rs35
1 files changed, 31 insertions, 4 deletions
diff --git a/pkgs/by-name/mp/mpdpopm/src/config.rs b/pkgs/by-name/mp/mpdpopm/src/config.rs
index e6c01599..2d9c466b 100644
--- a/pkgs/by-name/mp/mpdpopm/src/config.rs
+++ b/pkgs/by-name/mp/mpdpopm/src/config.rs
@@ -54,6 +54,27 @@ pub enum Connection {
TCP { host: String, port: u16 },
}
+impl Connection {
+ pub fn new() -> Result<Self> {
+ let env = env::var("MPD_HOST")?;
+
+ if env.starts_with("/") {
+ // We assume that this is a path to a local socket
+ Ok(Self::Local {
+ path: PathBuf::from(env),
+ })
+ } else {
+ todo!("Not yet able to auto-parse, MPD_HOST for remote connection")
+ }
+ }
+}
+
+impl Default for Connection {
+ fn default() -> Self {
+ Self::new().expect("Could not generate default connection")
+ }
+}
+
#[cfg(test)]
mod test_connection {
use super::Connection;
@@ -118,16 +139,22 @@ pub struct Config {
}
impl Default for Config {
- fn default() -> Config {
- Config {
+ fn default() -> Self {
+ Self::new().unwrap()
+ }
+}
+
+impl Config {
+ fn new() -> Result<Self> {
+ Ok(Self {
_version: String::from("1"),
log: [LOCALSTATEDIR, "log", "mppopmd.log"].iter().collect(),
- conn: Connection::default(),
+ conn: Connection::new()?,
local_music_dir: [PREFIX, "Music"].iter().collect(),
played_thresh: 0.6,
poll_interval_ms: 5000,
commands_chan: String::from("unwoundstack.com:commands"),
- }
+ })
}
}