Class: Fum::Commands::Terminate

Inherits:
Fum::Command show all
Defined in:
lib/fum/commands/terminate.rb

Instance Method Summary collapse

Methods inherited from Fum::Command

#initialize, #stage

Methods included from Util

#die

Constructor Details

This class inherits a constructor from Fum::Command

Instance Method Details

#execute(options) ⇒ Object

  • :type



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fum/commands/terminate.rb', line 20

def execute(options)
  stage_name = options[:stage_name]
  stage_decl = stage(@application.main_decl, stage_name)

  analyzer = StageAnalyzer.new(stage_decl)

  analyzer.analyze(options)

  env_info = analyzer.env_map.values

  targets = []

  if options[:all]
    targets = env_info.map { |e| e[:env] }
  else
    targets = env_info.select { |e| e[:state] == :inactive }.map { |e| e[:env] }
  end

  if targets.length > 0
    targets.each { |target|
      if target.ready?
        puts "Terminating inactive environment #{target.name}."
        target.destroy
      end

    }
  else
    puts "No environments to terminate."
  end

end

#parse_optionsObject



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

def parse_options
  opts = Trollop::options do
    banner "usage: terminate [options] <stage>, where options are:"
    opt :all, "Terminate all environments for this stage (use with caution)."
  end
  if ARGV.empty?
    die "Please specify a stage name type to terminate."
  end
  opts[:stage_name] = ARGV.shift
  opts
end