diff --git a/.gitignore b/.gitignore index af99834..1fbc882 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /target result .direnv -noise.zsh diff --git a/build.rs b/build.rs index 2e95170..2421fa1 100644 --- a/build.rs +++ b/build.rs @@ -1,19 +1,39 @@ -use clap::CommandFactory; -use clap_mangen::generate_to; +use clap::{Command, CommandFactory}; +// use clap_complete as complete; +use clap_mangen as mangen; +// use complete::Shell; +use std::{path::PathBuf, str::FromStr}; #[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_to(cmd, &out_dir)?; - println!("cargo:warning=OUT_DIR: {out_dir:?}"); + generate_manpage(cmd, out_dir.clone())?; + + // eprintln!("{out_dir:?}"); + // println!("cargo:warning=out_dir: {out_dir:?}"); Ok(()) } diff --git a/flake.nix b/flake.nix index 291aef4..5c68f0d 100644 --- a/flake.nix +++ b/flake.nix @@ -7,10 +7,10 @@ outputs = { + self, nixpkgs, utils, naersk, - ... }: utils.lib.eachDefaultSystem ( system: @@ -32,6 +32,10 @@ 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 3a13e00..0630136 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,8 +5,8 @@ use clap_complete::Shell; #[command( author = "Nox Sluijtman", version, - 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'.", + about, + long_about = "A small, opinionated MPD client", name = "noise" )] #[command(propagate_version = true)] @@ -19,36 +19,35 @@ pub struct Cli { #[arg(short, long, global = true)] pub verbose: bool, /// Hostname where MPD listens at - #[arg(short = 'H', long, global = true, value_hint = ValueHint::Hostname)] + #[arg(short = 'H', long, global = true)] 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 playback - #[command(visible_alias = "t")] + /// Toggle MPD stream 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(value_hint = ValueHint::Other)] + #[arg(short, long, value_hint = ValueHint::Other)] track: Option, }, /// Set or get crossfade - #[command(visible_alias = "fade")] Crossfade { - #[arg(value_hint = ValueHint::Other)] + #[arg(short, long, value_hint = ValueHint::Other)] seconds: Option, }, ///Update still needs some work @@ -58,7 +57,6 @@ 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)] @@ -71,8 +69,7 @@ pub enum Commands { // #[arg(short, long)] // insert: Option, }, - /// Query database autistically - #[command(visible_alias = "fd")] + /// Query database differently Find { ///Search query #[arg(trailing_var_arg = true, value_hint = ValueHint::Other)] @@ -84,7 +81,6 @@ pub enum Commands { append: bool, }, /// List items in the current queueueu - #[command(visible_alias = "ls")] List { #[arg(short, long)] file: bool, @@ -94,20 +90,5 @@ 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 0be8bea..2931319 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,7 +76,7 @@ fn main() { let thing = conn.update().unwrap(); println!("{thing}") } - Commands::Current => (), + Commands::Current => (), // this is basically the same as having no command Commands::Clear => conn.clear().unwrap(), Commands::Search { query, max } => { let query = query.join(" "); @@ -118,30 +118,6 @@ 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 @@ -159,14 +135,8 @@ 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_or("Unknown".into()), - song.title.unwrap() - ) + format!("{} - {}", song.artist.unwrap(), song.title.unwrap()) } trait QuickFmt {