1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#![allow(
clippy::cast_possible_truncation,
clippy::cast_precision_loss,
clippy::cast_sign_loss
)]
use std::path::PathBuf;
use std::process::ExitCode;
use clap::{Parser, Subcommand};
mod cli;
#[derive(Parser)]
#[command(name = "rsbts", version)]
#[command(about = "A safe, plan-first music library manager")]
struct Cli {
/// Path to config file
#[arg(short, long, global = true)]
config: Option<PathBuf>,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Preview and import albums into the library
Import {
/// Paths to scan
#[arg(required = true)]
paths: Vec<PathBuf>,
/// Copy files into the library
#[arg(short = 'C', long, conflicts_with_all = ["move", "link"])]
copy: bool,
/// Move files into the library after committing metadata
#[arg(short = 'M', long, conflicts_with_all = ["copy", "link"])]
r#move: bool,
/// Create symbolic links in the library
#[arg(short = 'L', long, conflicts_with_all = ["copy", "move"])]
link: bool,
/// Preview decisions and destinations without changing files or the database
#[arg(long)]
dry_run: bool,
/// Accept only candidates that pass every strict confidence gate
#[arg(short = 'y', long)]
yes: bool,
},
/// List tracks or albums
#[command(name = "ls", alias = "list")]
List {
/// Track query, or album/album-artist substring with --album
query: Option<String>,
/// Show albums instead of tracks
#[arg(short, long)]
album: bool,
},
/// Show library statistics
Stats,
/// Check database and file consistency
Audit,
/// Re-read tags for matching library items
Update {
/// Query to filter items
query: Option<String>,
},
/// Remove matching items from the library
#[command(name = "rm", alias = "remove")]
Remove {
/// Query to match items
query: String,
/// Also delete files from disk after quarantining them
#[arg(short, long)]
delete: bool,
/// Preview the complete removal set without changing anything
#[arg(long)]
dry_run: bool,
/// Confirm the complete removal set non-interactively
#[arg(short = 'y', long)]
yes: bool,
},
/// Modify metadata stored in the library database
Modify {
/// Query to match items
query: String,
/// Field=value pairs
#[arg(required = true)]
fields: Vec<String>,
},
}
#[tokio::main]
async fn main() -> ExitCode {
let arguments = Cli::parse();
match cli::run(arguments.command, arguments.config).await {
Ok(cli::Outcome::Success) => ExitCode::SUCCESS,
Ok(cli::Outcome::Partial) => ExitCode::from(2),
Err(error) => {
eprintln!("rsbts: {}", cli::terminal_safe(error));
ExitCode::FAILURE
}
}
}