Class: LitmusPaper::CLI::Admin::Force

Inherits:
Command
  • Object
show all
Defined in:
lib/litmus_paper/cli/admin/force.rb

Class Method Summary collapse

Methods inherited from Command

_default_options, _extend_default_parser

Class Method Details

.build_request(options, args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/litmus_paper/cli/admin/force.rb', line 9

def self.build_request(options, args)
  options.merge! _default_options
  opt_parser = _extend_default_parser(options) do |opts|
    opts.banner = "Usage: litmusctl force <up|down|health N> [service] [options]"
    opts.on("-d", "--delete", "Remove status file") do
      options[:delete] = true
    end
    opts.on("-r", "--reason=reason", String, "Reason for status file") do |reason|
      options[:reason] = reason.gsub("\n", " ")
    end
  end

  opt_parser.parse! args
  if args[0] == "health" && !options[:delete]
    direction, value, service = args
  else
    direction, service = args
  end
  path = service ? "/#{service}/#{direction}" : "/#{direction}"

  if options[:delete]
    request = Net::HTTP::Delete.new(path)
  else
    if !options.has_key?(:reason)
      print "Reason? "
      options[:reason] = STDIN.gets.chomp.gsub("\n", " ")
    end
    request = Net::HTTP::Post.new(path)
    params = {'reason' => options[:reason]}
    params.merge!({'health' => value}) if direction == 'health'
    request.set_form_data(params)
  end

  request
end

.descriptionObject



5
6
7
# File 'lib/litmus_paper/cli/admin/force.rb', line 5

def self.description
  "Force services up or down"
end