noise-rs/src/main.rs

77 lines
2.4 KiB
Rust
Raw Normal View History

2025-06-07 11:24:20 +02:00
extern crate mpd;
2025-07-08 18:55:41 +02:00
mod noise;
use noise::{commands::Noise, parser::*};
2025-07-02 23:07:43 +02:00
use clap::{Command, CommandFactory, Parser};
use clap_complete::{generate, Generator};
2025-07-08 18:55:41 +02:00
use mpd::Client;
use std::io;
2025-06-07 11:43:42 +02:00
2025-07-02 23:07:43 +02:00
fn print_completions<G: Generator>(generator: G, cmd: &mut Command) {
generate(
generator,
cmd,
cmd.get_name().to_string(),
&mut io::stdout(),
);
2025-06-07 11:24:20 +02:00
}
fn main() {
2025-07-02 23:07:43 +02:00
let cli = Cli::parse();
if let Some(completions) = cli.completions {
let mut cmd = Cli::command();
2025-07-08 18:55:41 +02:00
eprintln!("Generatig completion file for {completions:?}...");
2025-07-02 23:07:43 +02:00
print_completions(completions, &mut cmd);
return;
}
2025-06-21 21:16:26 +02:00
let host = cli.host.unwrap_or("localhost:6600".into());
2025-06-08 22:53:08 +02:00
let mut conn = Client::connect(host).expect("Connection failed");
2025-06-13 13:09:18 +02:00
if let Some(cmd) = &cli.command {
match cmd {
2025-07-09 18:20:50 +02:00
Commands::Play { track } => Noise::play(&mut conn, *track),
2025-07-08 18:55:41 +02:00
Commands::Stop => conn.stop().unwrap(),
Commands::Toggle => conn.toggle(),
Commands::Next => conn.next().unwrap(),
Commands::Prev => conn.prev().unwrap(),
2025-07-08 18:55:41 +02:00
Commands::List { file } => conn.list_queue(*file, cli.verbose),
2025-07-06 00:20:06 +02:00
Commands::Current => (),
Commands::Clear => conn.clear().unwrap(),
2025-07-09 18:20:50 +02:00
Commands::Search { query, max } => Noise::search(&mut conn, query, *max),
Commands::Find { query, max, append } => Noise::find(&mut conn, query, *max, *append),
Commands::Crossfade { seconds } => Noise::crossfade(&mut conn, *seconds),
2025-07-08 18:55:41 +02:00
Commands::Shuffle => conn.shuf(),
Commands::Repeat => conn.toggle_repeat(),
Commands::Random => conn.toggle_random(),
Commands::Single => conn.toggle_single(),
Commands::Consume => conn.toggle_consume(),
Commands::Volume { percentage } => conn.vol(*percentage),
Commands::Munch => conn.munch(),
Commands::Length => conn.length(),
2025-06-07 11:43:42 +02:00
}
if let Commands::Stop
| Commands::List { .. }
| Commands::Clear
| Commands::Search { .. }
| Commands::Find { .. }
| Commands::Crossfade { .. }
| Commands::Shuffle = cmd
{
return;
}
2025-06-07 11:43:42 +02:00
}
2025-07-09 18:20:50 +02:00
let things: Vec<String> = conn
.queue()
.unwrap()
.iter()
.map(|x| x.place.unwrap().pos.to_string())
.collect();
println!("{things:?}");
2025-07-08 18:55:41 +02:00
println!("{}", conn.get_status(cli.verbose));
2025-06-08 22:53:08 +02:00
}