aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cli.rs41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index f5fdd2c..e4bb484 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -92,6 +92,13 @@ 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 /// Query string (e.g. \"J\", \"Artist/\", \"Artist/Album/\")
99 #[arg(value_name = "QUERY")]
100 query: String,
101 },
95} 102}
96 103
97#[derive(Subcommand)] 104#[derive(Subcommand)]
@@ -235,11 +242,43 @@ impl Cli {
235 } 242 }
236 } 243 }
237 } 244 }
245 Commands::DbComplete { query } => {
246 // Unescape shell escapes in the input query
247 let query = {
248 let mut unescaped = String::with_capacity(query.len());
249 let mut chars = query.chars();
250 while let Some(c) = chars.next() {
251 if c == '\\' {
252 if let Some(next) = chars.next() {
253 unescaped.push(next);
254 }
255 } else {
256 unescaped.push(c);
257 }
258 }
259 unescaped
260 };
261
262 let config = match Config::load() {
263 Ok(c) => c,
264 Err(_) => return Ok(()),
265 };
266 let db = match Database::open(&config) {
267 Ok(d) => d,
268 Err(_) => return Ok(()),
269 };
270
271 let results = db.complete(&query).unwrap_or_default();
272
273 for r in &results {
274 println!("{r}");
275 }
276 }
238 Commands::Completions { shell } => { 277 Commands::Completions { shell } => {
239 let full = Cli::command(); 278 let full = Cli::command();
240 let subcommands: Vec<Command> = full 279 let subcommands: Vec<Command> = full
241 .get_subcommands() 280 .get_subcommands()
242 .filter(|s| s.get_name() != "completions") 281 .filter(|s| s.get_name() != "completions" && s.get_name() != "db-complete")
243 .cloned() 282 .cloned()
244 .collect(); 283 .collect();
245 let cmd_name = full.get_name().to_string(); 284 let cmd_name = full.get_name().to_string();