Permalink
Browse files

Add CLI for discovering with Thor

  • Loading branch information...
1 parent e1a9bbb commit 0de85c7f95a8164b03521dcfe97a22ea6a3dc412 @soffes soffes committed Dec 24, 2012
Showing with 23 additions and 13 deletions.
  1. +2 −2 bin/{sonos-discover → sonos}
  2. +0 −11 bin/sonos-discover-multiple
  3. +20 −0 lib/sonos/cli.rb
  4. +1 −0 sonos.gemspec
@@ -2,6 +2,6 @@
lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
-require 'sonos'
+require 'sonos/cli'
-puts Sonos.discover.ip
+Sonos::Cli.start
@@ -1,11 +0,0 @@
-#!/usr/bin/env ruby
-
-lib = File.expand_path('../../lib', __FILE__)
-$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
-require 'sonos'
-
-if speaker = Sonos.discover
- speaker.topology.each do |node|
- puts "#{node.name.ljust(20)} #{node.ip}"
- end
-end
View
@@ -0,0 +1,20 @@
+require 'thor'
+require 'sonos'
+
+module Sonos
+ class Cli < Thor
+ desc 'discover', 'Finds the IP address of a Sonos device on your network'
+ method_option :all, type: :boolean, aliases: '-a', desc: 'Find all of the IP address instead of the first one discoverd'
+ def discover
+ speaker = Sonos.discover
+
+ if options[:all]
+ speaker.topology.each do |node|
+ puts "#{node.name.ljust(20)} #{node.ip}"
+ end
+ else
+ puts "#{speaker.zone_name.ljust(20)} #{speaker.ip}"
+ end
+ end
+ end
+end
View
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
gem.require_paths = ['lib']
gem.add_dependency 'savon', '~> 2.0.2'
+ gem.add_dependency 'thor'
end

0 comments on commit 0de85c7

Please sign in to comment.