Module: Formatron::CLI::Destroy

Defined in:
lib/formatron/cli/destroy.rb

Overview

CLI command for destroy

Instance Method Summary collapse

Instance Method Details

#destroy_action(c) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/formatron/cli/destroy.rb', line 34

def destroy_action(c)
  c.action do |args, options|
    directory = destroy_directory options
    target = destroy_target args[0], directory
    formatron = Formatron.new(
      credentials: destroy_credentials(options),
      directory: directory,
      target: target
    )
    formatron.destroy if destroy_ok options, formatron, target
  end
end

#destroy_credentials(options) ⇒ Object



12
13
14
15
16
17
# File 'lib/formatron/cli/destroy.rb', line 12

def destroy_credentials(options)
  options.credentials ||
    Generators::Credentials.default_credentials(
      destroy_directory(options)
    )
end

#destroy_directory(options) ⇒ Object



8
9
10
# File 'lib/formatron/cli/destroy.rb', line 8

def destroy_directory(options)
  options.directory || Dir.pwd
end

#destroy_formatron_commandObject



47
48
49
50
51
52
53
54
# File 'lib/formatron/cli/destroy.rb', line 47

def destroy_formatron_command
  command :destroy do |c|
    c.syntax = 'formatron destroy [options] [TARGET]'
    c.summary = 'Destroy a Formatron stack'
    c.description = 'Destroy a Formatron stack'
    destroy_action c
  end
end

#destroy_ok(options, formatron, target) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/formatron/cli/destroy.rb', line 26

def destroy_ok(options, formatron, target)
  options.yes || !formatron.protected? || agree(
    "Are you sure you wish to destroy protected target: #{target}?"
  ) do |q|
    q.default = 'no'
  end
end

#destroy_target(target, directory) ⇒ Object



19
20
21
22
23
24
# File 'lib/formatron/cli/destroy.rb', line 19

def destroy_target(target, directory)
  target || choose(
    'Target?',
    *Config.targets(directory: directory)
  )
end