Skip to content
Browse files

Better POSIX compatibility. Correct return codes. Fixed quiet return …

…'nil'.
  • Loading branch information...
1 parent b625d48 commit 0a1697d7671e7e5e9718e9d109c4f3425f49c932 @matiaskorhonen committed
Showing with 29 additions and 25 deletions.
  1. +2 −3 bin/wol
  2. +27 −22 lib/wol/runner.rb
View
5 bin/wol
@@ -1,8 +1,7 @@
#!/usr/bin/env ruby
-$LOAD_PATH.push File.join(File.dirname(__FILE__), "/../lib")
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'wol'
-Wol::Runner.run!
-
+exit Wol::Runner.run!(ARGV)
View
49 lib/wol/runner.rb
@@ -117,36 +117,41 @@ def self.version
# Send WOL MagicPackets based on the parsed options
def self.wake(options = {})
- begin
- if options[:file]
- hosts = ParseFile.read_and_parse_file(options[:file])
+ if options[:file]
+ hosts = ParseFile.read_and_parse_file(options[:file])
- for host in hosts
- options[:address], options[:macs], options[:port] = host[:address], host[:mac], host[:port]
+ for host in hosts
+ options[:address], options[:macs], options[:port] = host[:address], host[:mac], host[:port]
- puts WakeOnLan.new(options).wake
- end
- elsif options[:macs]
- options[:macs].each do |mac|
- options[:mac] = mac
- puts WakeOnLan.new(options).wake
- end
- else
- puts "You have to specify a file or MAC address"
+ message = WakeOnLan.new(options).wake.to_s
+ puts message unless options[:quiet]
+ return 0
end
- rescue Exception => e
- puts "An error occured. Please check your inputs."
- puts "If you used a file, please check that it is properly formatted."
- STDERR.puts e.message
- exit(-1)
+ elsif !options[:macs].empty?
+ options[:macs].each do |mac|
+ options[:mac] = mac
+ message = WakeOnLan.new(options).wake.to_s
+ puts message unless options[:quiet]
+ return 0
+ end
+ else
+ puts "You have to specify a file or MAC address"
end
end
# Parse the command line options, then use them to wake up any given hosts.
- def self.run!
- options = parse(ARGV)
+ def self.run!(argv)
+ begin
+ options = parse(argv)
- wake(options)
+ wake(options)
+ return 0
+ rescue Exception => e
+ puts "An error occured. Please check your inputs."
+ puts "If you used a file, please check that it is properly formatted."
+ STDERR.puts e.message
+ return -1
+ end
end
end
end

0 comments on commit 0a1697d

Please sign in to comment.
Something went wrong with that request. Please try again.