Better error and notification handling
This commit is contained in:
parent
c9ac64d504
commit
eddf2231e9
5 changed files with 45 additions and 30 deletions
15
src/main.rs
15
src/main.rs
|
@ -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(());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue