Skip to content

Commit

Permalink
Add CLI for discovering with Thor
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Dec 24, 2012
1 parent e1a9bbb commit 0de85c7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions bin/sonos-discover → bin/sonos
Expand Up @@ -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
11 changes: 0 additions & 11 deletions bin/sonos-discover-multiple

This file was deleted.

20 changes: 20 additions & 0 deletions lib/sonos/cli.rb
@@ -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
1 change: 1 addition & 0 deletions sonos.gemspec
Expand Up @@ -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.