Class: Terminate::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/terminate/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



5
6
7
8
9
10
11
12
13
14
# File 'lib/terminate/options.rb', line 5

def initialize
  @help = ''
  @options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: wait_stop [pid] [options]"
    opts.on('-t', '--timeout=TIMEOUT', 'Timeout to kill(seconds, default is 10)') { |v| @options[:timeout] = v }
    opts.on('-s', '--signal=SIGNAL', 'SIGNAL to terminate(default TERM)') { |v| @options[:signal] = v }
    @help = opts.to_s
  end.parse!
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



3
4
5
# File 'lib/terminate/options.rb', line 3

def help
  @help
end

Instance Method Details

#pidObject



16
17
18
# File 'lib/terminate/options.rb', line 16

def pid
  ARGV[0].to_i
end

#signalObject



25
26
27
# File 'lib/terminate/options.rb', line 25

def signal
  @options[:signal] || 'TERM'
end

#timeoutObject



20
21
22
23
# File 'lib/terminate/options.rb', line 20

def timeout
  timeout = @options[:timeout].to_i
  timeout <= 0 ? 10 : timeout
end