From 17a64c9526e5f8a20183f15597cda2cb93ee97c8 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sun, 23 Feb 2020 21:13:55 +0000 Subject: [PATCH] Add subcommand to group and ungroup from a master --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.rs b/src/main.rs index c621f79..51bcffd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use std::net::IpAddr; use sonos::Speaker; use failure::Fallible; +use crate::discovery::find_speaker_by_name; fn argparse<'a, 'b>() -> clap::App<'a, 'b> { use clap::{App, AppSettings, Arg, SubCommand}; @@ -44,6 +45,12 @@ fn argparse<'a, 'b>() -> clap::App<'a, 'b> { .arg(Arg::with_name("uri").help("Queue position to skip to or a Sonos URI to play").index(1).conflicts_with_all(&["tv", "line-in"])) ) ) + .subcommand(SubCommand::with_name("group").about("Group this speaker with the given master") + .arg(Arg::with_name("MASTER") + .help("Name of the speaker to group with") + .required(true) + .index(1))) + .subcommand(SubCommand::with_name("ungroup").about("Ungroup this speaker from the master")) .subcommand(SubCommand::with_name("seek").about("Seek to a specific timestamp on the current track") .arg(Arg::with_name("TIMESTAMP") .help("hh:mm:ss/mm:ss") @@ -93,6 +100,14 @@ async fn main() -> Fallible<()> { _ => print_struct!(args, &Track::new(&speaker).await?) } }, + ("group", Some(sub)) => { + let master = sub.value_of("MASTER").expect("master"); + speaker.group(&match master.parse::() { + Ok(ip) => Speaker::from_ip(ip).await?, + Err(_) => discovery::find_speaker_by_name(master).await?, + }).await? + }, + ("ungroup", _) => speaker.ungroup().await?, ("info", _) => print_struct!(args, &Info::new(&speaker)), ("volume", Some(sub)) => match sub.value_of("VOLUME") { Some(volume) => speaker.set_volume(volume.parse()?).await?, -- libgit2 1.7.2