From 8daf40d59e9c20d2f95420a02c186aaeb0543450 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Wed, 2 Jul 2025 23:29:01 +0200 Subject: [PATCH 1/5] Documentation and a few aliases --- src/cli.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 0630136..f298bf9 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,7 +19,7 @@ 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 @@ -32,20 +32,23 @@ pub struct Cli { #[derive(Subcommand, Debug, PartialEq)] pub enum Commands { - /// Toggle MPD stream + /// Toggle MPD playback 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)] track: Option, }, /// Set or get crossfade + #[command(visible_alias = "fade")] Crossfade { #[arg(short, long, value_hint = ValueHint::Other)] seconds: Option, @@ -57,6 +60,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 +73,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 +86,7 @@ pub enum Commands { append: bool, }, /// List items in the current queueueu + #[command(visible_alias = "ls")] List { #[arg(short, long)] file: bool, From cbcb8fef3383b43dff409f1a24d1e767ced86039 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Wed, 2 Jul 2025 23:32:51 +0200 Subject: [PATCH 2/5] Ergonomics --- src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index f298bf9..f9bceca 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -44,7 +44,7 @@ pub enum Commands { /// 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 From ab77d39ee04c90cf8347a36f4f69ceea1b5366cd Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Wed, 2 Jul 2025 23:34:24 +0200 Subject: [PATCH 3/5] Ergonomics pt2 --- src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index f9bceca..75d5400 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -50,7 +50,7 @@ pub enum Commands { /// 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 From 293da4f33021c700fe1ee830e55b9c62ed6ba1c6 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Thu, 3 Jul 2025 23:01:21 +0200 Subject: [PATCH 4/5] Cleanup --- build.rs | 28 ++++------------------------ flake.nix | 6 +----- src/cli.rs | 4 +--- 3 files changed, 6 insertions(+), 32 deletions(-) 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 75d5400..d197c76 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -25,14 +25,12 @@ pub struct Cli { /// 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 playback + #[command(visible_alias = "t")] Toggle, /// Skip to the next track #[command(visible_alias = "skip")] From f0ba8bf5933d19b39ece626139c3ed7e6b583f96 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Sun, 6 Jul 2025 00:20:06 +0200 Subject: [PATCH 5/5] Few more commands --- .gitignore | 1 + src/cli.rs | 15 +++++++++++++++ src/main.rs | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) 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/src/cli.rs b/src/cli.rs index d197c76..3a13e00 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -94,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 {