diff --git a/src/main.rs b/src/main.rs index b64916b..c2ef2f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,9 +38,9 @@ enum Command { }, /// Build a playlist from similar artists Build { - /// Print track scores - #[arg(short)] - verbose: bool, + /// Verbosity level (-v, -vv) + #[arg(short, action = clap::ArgAction::Count)] + verbose: u8, /// Queue in MPD #[arg(short, conflicts_with = "airsonic")] mpd: bool, @@ -65,7 +65,7 @@ enum Command { } struct BuildOptions { - verbose: bool, + verbose: u8, mpd: bool, airsonic: bool, shuffle: bool, @@ -358,10 +358,11 @@ fn build_playlist( let scored = playlist::score_tracks(conn, &artists, opts.popularity_bias); - if opts.verbose { + if opts.verbose >= 1 { let mut sorted = scored.iter().collect::>(); sorted.sort_by(|a, b| b.score.partial_cmp(&a.score).unwrap_or(std::cmp::Ordering::Equal)); - for t in &sorted { + let limit = if opts.verbose >= 2 { sorted.len() } else { 50.min(sorted.len()) }; + for t in &sorted[..limit] { eprintln!("{:.4}\t{:.4}\t{:.4}\t{}\t{}", t.score, t.similarity, t.popularity, t.artist, t.path); } } @@ -418,7 +419,7 @@ fn output_tracks( std::process::exit(1); } }; - if let Err(e) = client.create_playlist(seed_name, tracks, conn, opts.verbose) { + if let Err(e) = client.create_playlist(seed_name, tracks, conn, opts.verbose >= 1) { eprintln!("Airsonic error: {e}"); std::process::exit(1); }