Class: Igp::Shell
- Inherits:
-
Object
- Object
- Igp::Shell
- Defined in:
- lib/igp/shell.rb
Overview
class that groks the igp command line options and invokes the ping task
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
17 18 19 20 21 22 23 24 25 |
# File 'lib/igp/shell.rb', line 17 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
7 8 9 |
# File 'lib/igp/shell.rb', line 7 def @options end |
#uri ⇒ Object (readonly)
holds the URI object representing the ping target
9 10 11 |
# File 'lib/igp/shell.rb', line 9 def uri @uri end |
Class Method Details
.usage ⇒ Object
prints usage/help information
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 106 107 |
# File 'lib/igp/shell.rb', line 70 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
53 54 55 56 57 58 59 60 |
# File 'lib/igp/shell.rb', line 53 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
66 67 68 |
# File 'lib/igp/shell.rb', line 66 def usage self.class.usage end |