Better error and notification handling

This commit is contained in:
Nox Sluijtman 2025-07-23 13:18:52 +02:00
parent c9ac64d504
commit eddf2231e9
Signed by: Egg
SSH key fingerprint: SHA256:2sG9X3C7Xvq2svGumz1/k7cm8l4G9+qAtAeugqB4J9M
5 changed files with 45 additions and 30 deletions

View file

@ -5,7 +5,7 @@ use noise::{commands::Noise, parser::*};
use clap::{Command, CommandFactory, Parser};
use clap_complete::{generate, Generator};
use mpd::Client;
use mpd::{error::Error, Client};
use std::io;
fn print_completions<G: Generator>(generator: G, cmd: &mut Command) {
@ -17,19 +17,22 @@ fn print_completions<G: Generator>(generator: G, cmd: &mut Command) {
);
}
fn main() {
fn main() -> Result<(), Error> {
let cli = Cli::parse();
if let Some(completions) = cli.completions {
let mut cmd = Cli::command();
eprintln!("Generatig completion file for {completions:?}...");
print_completions(completions, &mut cmd);
return;
return Ok(());
}
let host = cli.host.unwrap_or("localhost:6600".into());
let mut conn = Client::connect(host).expect("Connection failed");
let mut conn = match Client::connect(host) {
Ok(client) => client,
Err(err) => return Err(err),
};
if let Some(cmd) = &cli.command {
match cmd {
@ -63,7 +66,7 @@ fn main() {
| Commands::Volume { .. }
| Commands::Shuffle = cmd
{
return;
return Ok(());
}
}
let _things: Vec<String> = conn
@ -72,6 +75,6 @@ fn main() {
.iter()
.map(|x| x.place.unwrap().pos.to_string())
.collect();
// println!("{things:?}");
println!("{}", conn.get_status(cli.verbose));
return Ok(());
}