Improved verbosity on build

This commit is contained in:
Connor Johnstone
2026-03-05 13:40:16 -05:00
parent 552caff9b8
commit aa3b8c4478

View File

@@ -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::<Vec<_>>();
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);
}