lib/igp/shell.rb in igp-0.0.3 vs lib/igp/shell.rb in igp-1.0.0

- old
+ new

@@ -1,10 +1,9 @@ require 'uri' # class that groks the igp command line options and invokes the ping task class Igp::Shell - # holds the parsed options attr_reader :options # holds the URI object representing the ping target attr_reader :uri @@ -12,16 +11,17 @@ # # +options+ is expected to be the hash structure as provided by GetOptions.new(..) # # +args+ is the remaining command line arguments # - def initialize(options,args) + def initialize(options, args) defaults = { - :interval => 1 + interval: 1 } - @options = defaults.merge( (options||{}).each{|k,v| {k => v} } ) + @options = defaults.merge((options || {}).each { |k, v| { k => v } }) return unless args.first + resolve_addressing args.first normalise_options end protected @@ -30,11 +30,11 @@ def resolve_addressing(host) @uri = URI.parse(host) unless uri.scheme @options[:type] = :icmp @options[:host] = uri.to_s - @options[:url] = "#{@options[:type].to_s}://#{@options[:host]}" + @options[:url] = "#{@options[:type]}://#{@options[:host]}" return end @options[:url] = uri.to_s @options[:type] = uri.scheme.to_sym @options[:port] = uri.port @@ -50,59 +50,61 @@ public # runs the ping task def run case options[:type] - when :icmp,:http,:https,:tcp,:udp,:ldap,:ldaps + # TODO: LDAP was retired from net-ping. to add back in one way or another + when :icmp, :http, :https, :tcp, :udp # :ldap, :ldaps Igp::Base.new(options).run else usage end end # defines the valid command line options - OPTIONS = %w(help verbose interval=i limit=i) + OPTIONS = %w[help verbose interval=i limit=i].freeze # prints usage/help information def usage self.class.usage end + # prints usage/help information def self.usage - $stderr.puts <<-EOS + $stderr.puts <<~EOS -It goes PING! v#{Igp::VERSION} -=================================== + It goes PING! v#{Igp::VERSION} + =================================== -Usage: - igp [options] uri - -Options: - -h | --help :shows command help - -i= | --interval=seconds (default: 1 second) - -l= | --limit=number of tests (default: infinite) + Usage: + igp [options] uri -The uri specifies the protocol, hostname and port. -The ICMP protocol is assumed if not specified. -The default well-known port is assumed if not specified. + Options: + -h | --help :shows command help + -i= | --interval=seconds (default: 1 second) + -l= | --limit=number of tests (default: infinite) -Examples: + The uri specifies the protocol, hostname and port. + The ICMP protocol is assumed if not specified. + The default well-known port is assumed if not specified. - ICMP ping: - igp localhost - igp icmp://localhost + Examples: - UDP/TCP ping: - igp udp://localhost:123 - igp tcp://localhost:843 + ICMP ping: + igp localhost + igp icmp://localhost - HTTP/S ping: - igp http://localhost:8080 - igp https://localhost:4443 + UDP/TCP ping: + igp udp://localhost:123 + igp tcp://localhost:843 - LDAP/S ping: - igp ldap://localhost - igp ldaps://localhost:6636 + HTTP/S ping: + igp http://localhost:8080 + igp https://localhost:4443 EOS + # TODO: LDAP was retired from net-ping. to add back in one way or another + # LDAP/S ping: + # igp ldap://localhost + # igp ldaps://localhost:6636 end -end \ No newline at end of file +end