clean up address resolution

This commit is contained in:
figsoda 2020-11-15 17:24:35 -05:00
parent 6fe8b4b5cc
commit 45f77f87bd
2 changed files with 3 additions and 8 deletions

View file

@ -7,6 +7,5 @@ macro_rules! fail {
} }
fail!(connect addr = "Failed to connect to {}"); fail!(connect addr = "Failed to connect to {}");
fail!(parse_addr addr = "Faield to parse {} as an address");
fail!(parse_cfg path = "Failed to parse configuration file {}"); fail!(parse_cfg path = "Failed to parse configuration file {}");
fail!(read path = "Failed to read file {}"); fail!(read path = "Failed to read file {}");

View file

@ -25,7 +25,7 @@ use tokio::{
}; };
use tui::{backend::CrosstermBackend, widgets::ListState, Terminal}; use tui::{backend::CrosstermBackend, widgets::ListState, Terminal};
use std::{cmp::min, fs, io::stdout, process::exit}; use std::{cmp::min, fs, io::stdout, net::SocketAddr, process::exit};
use crate::{config::Config, mpd::Client}; use crate::{config::Config, mpd::Client};
@ -57,7 +57,7 @@ struct Opts {
/// Specify the address of the mpd server /// Specify the address of the mpd server
#[structopt(long, value_name = "address")] #[structopt(long, value_name = "address")]
address: Option<String>, address: Option<SocketAddr>,
/// Specify the config file /// Specify the config file
#[structopt(short, long, value_name = "file")] #[structopt(short, long, value_name = "file")]
@ -154,11 +154,7 @@ async fn run() -> Result<()> {
defaults::config() defaults::config()
}; };
let addr = &if let Some(addr) = opts.address { let addr = &opts.address.unwrap_or(cfg.address);
addr.parse().with_context(fail::parse_addr(addr))?
} else {
cfg.address
};
let mut idle_cl = Client::init(addr).await?; let mut idle_cl = Client::init(addr).await?;
let mut cl = Client::init(addr).await?; let mut cl = Client::init(addr).await?;