Class: Igp::Shell
- Inherits:
-
Object
- Object
- Igp::Shell
- Defined in:
- lib/igp/shell.rb
Constant Summary collapse
- OPTIONS =
defines the valid command line options
%w(help verbose interval=i limit=i)
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
holds the parsed options.
-
#uri ⇒ Object
readonly
holds the URI object representing the ping target.
Class Method Summary collapse
-
.usage ⇒ Object
prints usage/help information.
Instance Method Summary collapse
-
#initialize(options, args) ⇒ Shell
constructor
initializes the shell with command line argments:.
-
#run ⇒ Object
runs the ping task.
-
#usage ⇒ Object
prints usage/help information.
Constructor Details
#initialize(options, args) ⇒ Shell
initializes the shell with command line argments:
options
is expected to be the hash structure as provided by GetOptions.new(..)
args
is the remaining command line arguments
15 16 17 18 19 20 21 22 23 |
# File 'lib/igp/shell.rb', line 15 def initialize(,args) defaults = { :interval => 1 } @options = defaults.merge( (||{}).each{|k|k} ) return unless args.first resolve_addressing args.first end |
Instance Attribute Details
#options ⇒ Object (readonly)
holds the parsed options
5 6 7 |
# File 'lib/igp/shell.rb', line 5 def @options end |
#uri ⇒ Object (readonly)
holds the URI object representing the ping target
7 8 9 |
# File 'lib/igp/shell.rb', line 7 def uri @uri end |
Class Method Details
.usage ⇒ Object
prints usage/help information
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/igp/shell.rb', line 68 def self.usage $stderr.puts <<-EOS 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) 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. Examples: ICMP ping: igp localhost igp icmp://localhost UDP/TCP ping: igp udp://localhost:123 igp tcp://localhost:843 HTTP/S ping: igp http://localhost:8080 igp https://localhost:4443 LDAP/S ping: igp ldap://localhost igp ldaps://localhost:6636 EOS end |
Instance Method Details
#run ⇒ Object
runs the ping task
51 52 53 54 55 56 57 58 |
# File 'lib/igp/shell.rb', line 51 def run case [:type] when :icmp,:http,:https,:tcp,:udp,:ldap,:ldaps Igp::Base.new().run else usage end end |
#usage ⇒ Object
prints usage/help information
64 65 66 |
# File 'lib/igp/shell.rb', line 64 def usage self.class.usage end |