diff options
| author | salmonik <raisersoft@proton.me> | 2026-06-04 00:21:46 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-06-04 00:21:46 +0200 |
| commit | 1e48765ab39a679abcc4eac6927ad3bb58f7b438 (patch) | |
| tree | 5554f2a06bde693d4d9c39ed26f80677d61da991 /src/cli.rs | |
| parent | fix no metadata songs handling (diff) | |
| download | rsplayer-1e48765ab39a679abcc4eac6927ad3bb58f7b438.tar.gz rsplayer-1e48765ab39a679abcc4eac6927ad3bb58f7b438.zip | |
dirty, broken commit
Diffstat (limited to '')
| -rw-r--r-- | src/cli.rs | 36 |
1 files changed, 35 insertions, 1 deletions
| @@ -92,6 +92,16 @@ pub enum Commands { | |||
| 92 | #[arg(value_name = "SHELL")] | 92 | #[arg(value_name = "SHELL")] |
| 93 | shell: Option<String>, | 93 | shell: Option<String>, |
| 94 | }, | 94 | }, |
| 95 | #[clap(hide = true)] | ||
| 96 | /// Complete artists, albums, or tracks from database | ||
| 97 | DbComplete { | ||
| 98 | /// Entity type: artists, albums, or tracks | ||
| 99 | #[arg(value_name = "ENTITY")] | ||
| 100 | entity: String, | ||
| 101 | /// Optional prefix to match | ||
| 102 | #[arg(value_name = "PREFIX")] | ||
| 103 | prefix: Option<String>, | ||
| 104 | }, | ||
| 95 | } | 105 | } |
| 96 | 106 | ||
| 97 | #[derive(Subcommand)] | 107 | #[derive(Subcommand)] |
| @@ -235,11 +245,35 @@ impl Cli { | |||
| 235 | } | 245 | } |
| 236 | } | 246 | } |
| 237 | } | 247 | } |
| 248 | Commands::DbComplete { entity, prefix } => { | ||
| 249 | let config = match Config::load() { | ||
| 250 | Ok(c) => c, | ||
| 251 | Err(_) => return Ok(()), | ||
| 252 | }; | ||
| 253 | let db = match Database::open(&config) { | ||
| 254 | Ok(d) => d, | ||
| 255 | Err(_) => return Ok(()), | ||
| 256 | }; | ||
| 257 | let prefix = prefix.as_deref().unwrap_or(""); | ||
| 258 | let results: Vec<String> = match entity.as_str() { | ||
| 259 | "artists" => db.complete_artists(prefix).unwrap_or_default(), | ||
| 260 | "albums" => db.complete_albums(prefix).unwrap_or_default(), | ||
| 261 | "tracks" => db.complete_tracks(prefix).unwrap_or_default(), | ||
| 262 | _ => Vec::new(), | ||
| 263 | }; | ||
| 264 | let suffix = match entity.as_str() { | ||
| 265 | "artists" | "albums" => "/", | ||
| 266 | _ => "", | ||
| 267 | }; | ||
| 268 | for r in &results { | ||
| 269 | println!("{r}{suffix}"); | ||
| 270 | } | ||
| 271 | } | ||
| 238 | Commands::Completions { shell } => { | 272 | Commands::Completions { shell } => { |
| 239 | let full = Cli::command(); | 273 | let full = Cli::command(); |
| 240 | let subcommands: Vec<Command> = full | 274 | let subcommands: Vec<Command> = full |
| 241 | .get_subcommands() | 275 | .get_subcommands() |
| 242 | .filter(|s| s.get_name() != "completions") | 276 | .filter(|s| s.get_name() != "completions" && s.get_name() != "db-complete") |
| 243 | .cloned() | 277 | .cloned() |
| 244 | .collect(); | 278 | .collect(); |
| 245 | let cmd_name = full.get_name().to_string(); | 279 | let cmd_name = full.get_name().to_string(); |
