diff --git a/.gitignore b/.gitignore index 1fbc882..af99834 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target result .direnv +noise.zsh diff --git a/build.rs b/build.rs index 2421fa1..2e95170 100644 --- a/build.rs +++ b/build.rs @@ -1,39 +1,19 @@ -use clap::{Command, CommandFactory}; -// use clap_complete as complete; -use clap_mangen as mangen; -// use complete::Shell; -use std::{path::PathBuf, str::FromStr}; +use clap::CommandFactory; +use clap_mangen::generate_to; #[path = "src/cli.rs"] mod cli; use cli::*; -fn generate_manpage(cmd: Command, out_dir: PathBuf) -> std::io::Result<()> { - let _path = mangen::generate_to(cmd, &out_dir)?; - println!("cargo:warning=manpage is generated: {out_dir:?}"); - - Ok(()) -} - -// fn generate_completions(cmd: &mut Command, out_dir: PathBuf) -> std::io::Result<()> { -// let path = complete::generate_to(Shell::Zsh, cmd, "noise", out_dir)?; -// println!("cargo:warning=completion file is generated: {path:?}"); -// Ok(()) -// } - fn main() -> std::io::Result<()> { let out_dir = std::path::PathBuf::from(std::env::var_os("OUT_DIR").ok_or(std::io::ErrorKind::NotFound)?); - // let out_dir = PathBuf::from_str("./").unwrap(); - let cmd = Cli::command(); - generate_manpage(cmd, out_dir.clone())?; - - // eprintln!("{out_dir:?}"); - // println!("cargo:warning=out_dir: {out_dir:?}"); + generate_to(cmd, &out_dir)?; + println!("cargo:warning=OUT_DIR: {out_dir:?}"); Ok(()) } diff --git a/flake.nix b/flake.nix index 5c68f0d..291aef4 100644 --- a/flake.nix +++ b/flake.nix @@ -7,10 +7,10 @@ outputs = { - self, nixpkgs, utils, naersk, + ... }: utils.lib.eachDefaultSystem ( system: @@ -32,10 +32,6 @@ postInstall = with pkgs; lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' - # installShellCompletion --cmd noise \ - # --bash <($out/bin/fd --generate-completions bash) \ - # --fish <($out/bin/fd --generate-completions fish) - # installShellCompletion --zsh contrib/completion/_fd installShellCompletion --cmd noise \ --bash <($out/bin/noise --generate-completions bash) \ --zsh <($out/bin/noise --generate-completions zsh) \ diff --git a/src/cli.rs b/src/cli.rs index 0630136..3a13e00 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,8 +5,8 @@ use clap_complete::Shell; #[command( author = "Nox Sluijtman", version, - about, - long_about = "A small, opinionated MPD client", + about = "A small MPD client", + long_about = "I like how 'mpc' works for the most part, but I don't use most of its features and there are some parts of it that I feel could be more ergonomic. In comes 'noise', an opinionated, even more minimalist 'mpd' client than 'mpc'.", name = "noise" )] #[command(propagate_version = true)] @@ -19,35 +19,36 @@ pub struct Cli { #[arg(short, long, global = true)] pub verbose: bool, /// Hostname where MPD listens at - #[arg(short = 'H', long, global = true)] + #[arg(short = 'H', long, global = true, value_hint = ValueHint::Hostname)] pub host: Option, /// Generate shell completions #[arg(long = "generate-completions", value_enum)] pub completions: Option, - // /// Generate manpage - // #[arg(long = "generate-manpage", value_enum)] - // pub manpage: bool, } #[derive(Subcommand, Debug, PartialEq)] pub enum Commands { - /// Toggle MPD stream + /// Toggle MPD playback + #[command(visible_alias = "t")] Toggle, /// Skip to the next track + #[command(visible_alias = "skip")] Next, /// Revert to the previous track Prev, /// Stops playing Stop, /// Play queueueu + #[command(visible_alias = "start")] Play { - #[arg(short, long, value_hint = ValueHint::Other)] + #[arg(value_hint = ValueHint::Other)] track: Option, }, /// Set or get crossfade + #[command(visible_alias = "fade")] Crossfade { - #[arg(short, long, value_hint = ValueHint::Other)] + #[arg(value_hint = ValueHint::Other)] seconds: Option, }, ///Update still needs some work @@ -57,6 +58,7 @@ pub enum Commands { /// Clear current queueueu Clear, /// Query database + #[command(visible_alias = "q")] Search { ///Search query #[arg(trailing_var_arg = true, value_hint = ValueHint::Other)] @@ -69,7 +71,8 @@ pub enum Commands { // #[arg(short, long)] // insert: Option, }, - /// Query database differently + /// Query database autistically + #[command(visible_alias = "fd")] Find { ///Search query #[arg(trailing_var_arg = true, value_hint = ValueHint::Other)] @@ -81,6 +84,7 @@ pub enum Commands { append: bool, }, /// List items in the current queueueu + #[command(visible_alias = "ls")] List { #[arg(short, long)] file: bool, @@ -90,5 +94,20 @@ pub enum Commands { // position: Option, // }, /// Shuffles the current queueue + #[command(visible_alias = "scramble")] Shuffle, + /// Toggles repeat + Repeat, + /// Toggles random + Random, + /// Toggles consume + Consume, + /// Toggles single + Single, + /// Get or set volume + #[command(visible_alias = "vol")] + Volume { + #[arg(value_hint = ValueHint::Other)] + percentage: Option, + }, } diff --git a/src/main.rs b/src/main.rs index 2931319..0be8bea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,7 +76,7 @@ fn main() { let thing = conn.update().unwrap(); println!("{thing}") } - Commands::Current => (), // this is basically the same as having no command + Commands::Current => (), Commands::Clear => conn.clear().unwrap(), Commands::Search { query, max } => { let query = query.join(" "); @@ -118,6 +118,30 @@ fn main() { println!("Shuffling queueueu..."); conn.shuffle(..).unwrap(); } + Commands::Repeat => { + let repeat_state = conn.status().unwrap().repeat; + conn.repeat(!repeat_state).unwrap(); + } + Commands::Random => { + let random_state = conn.status().unwrap().random; + // conn.repeat(!random_state).unwrap(); + println!("{}", random_state) + } + Commands::Single => { + let single_state = conn.status().unwrap().single; + conn.single(!single_state).unwrap(); + } + Commands::Consume => { + let consume_state = conn.status().unwrap().consume; + conn.consume(!consume_state).unwrap(); + } + Commands::Volume { percentage } => { + if let Some(volume) = percentage { + conn.volume(*volume).unwrap() + } + let vol = conn.status().unwrap().volume; + println!("Volume at {vol}%") + } } if let Commands::Stop @@ -135,8 +159,14 @@ fn main() { println!("{}", get_status(conn, cli.verbose, n)); } +// fn toggle_state(mut client: Client, state: ) -> () {} + fn format_song(song: Song) -> String { - format!("{} - {}", song.artist.unwrap(), song.title.unwrap()) + format!( + "{} - {}", + song.artist.unwrap_or("Unknown".into()), + song.title.unwrap() + ) } trait QuickFmt {