Skip to main content

sonos_cli/cli/
complete.rs

1use clap_complete::engine::CompletionCandidate;
2
3use crate::config::Config;
4
5pub fn speaker_candidates() -> Vec<CompletionCandidate> {
6    let mut candidates = Vec::new();
7
8    let config = Config::load();
9    for (name, alias) in &config.aliases {
10        candidates.push(CompletionCandidate::new(alias).help(Some(name.into())));
11    }
12
13    if let Ok(system) = sonos_sdk::SonosSystem::new() {
14        for spk in system.speakers() {
15            candidates.push(CompletionCandidate::new(&spk.name));
16        }
17    }
18
19    candidates
20}
21
22pub fn group_candidates() -> Vec<CompletionCandidate> {
23    let mut candidates = Vec::new();
24
25    let config = Config::load();
26    for (name, alias) in &config.aliases {
27        candidates.push(CompletionCandidate::new(alias).help(Some(name.into())));
28    }
29
30    if let Ok(system) = sonos_sdk::SonosSystem::new() {
31        for spk in system.speakers() {
32            candidates.push(CompletionCandidate::new(&spk.name));
33        }
34    }
35
36    candidates
37}