Class: Igp::Shell

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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(options,args)
  defaults = {
    :interval => 1
  }
  @options = defaults.merge( (options||{}).each{|k|k} )
  return unless args.first
  resolve_addressing args.first
  normalise_options
end

Instance Attribute Details

#optionsObject (readonly)

holds the parsed options



7
8
9
# File 'lib/igp/shell.rb', line 7

def options
  @options
end

#uriObject (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

.usageObject

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

#runObject

runs the ping task



53
54
55
56
57
58
59
60
# File 'lib/igp/shell.rb', line 53

def run
  case options[:type]
  when :icmp,:http,:https,:tcp,:udp,:ldap,:ldaps
    Igp::Base.new(options).run
  else
    usage
  end
end

#usageObject

prints usage/help information



66
67
68
# File 'lib/igp/shell.rb', line 66

def usage
  self.class.usage
end