Module: Formatron::CLI::Provision

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

Overview

CLI command for provision

Instance Method Summary collapse

Instance Method Details

#provision_action(c) ⇒ Object

rubocop:disable Metrics/MethodLength



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/formatron/cli/provision.rb', line 44

def provision_action(c)
  c.action do |args, options|
    directory = provision_directory options
    target = provision_target args[0], directory
    formatron = Formatron.new(
      credentials: provision_credentials(options),
      directory: directory,
      target: target
    )
    formatron.provision(
      guid: options.guid
    ) if provision_ok options, formatron, target
  end
end

#provision_credentials(options) ⇒ Object



21
22
23
24
25
26
# File 'lib/formatron/cli/provision.rb', line 21

def provision_credentials(options)
  options.credentials ||
    Generators::Credentials.default_credentials(
      deploy_directory(options)
    )
end

#provision_directory(options) ⇒ Object



17
18
19
# File 'lib/formatron/cli/provision.rb', line 17

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

#provision_formatron_commandObject

rubocop:enable Metrics/MethodLength



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/formatron/cli/provision.rb', line 60

def provision_formatron_command
  command :provision do |c|
    c.syntax = 'formatron provision [options] [TARGET]'
    c.summary = 'Provision the instances in a Formatron ' \
                'stack using Opscode Chef'
    c.description = 'Provision the instances in a Formatron ' \
                    'stack using Opscode Chef'
    provision_options c
    provision_action c
  end
end

#provision_ok(options, formatron, target) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/formatron/cli/provision.rb', line 35

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

#provision_options(c) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/formatron/cli/provision.rb', line 8

def provision_options(c)
  c.option(
    '-g',
    '--guid STRING',
    'The guid of an instance to provision ' \
    '(will provision all instances if not specified)'
  )
end

#provision_target(target, directory) ⇒ Object



28
29
30
31
32
33
# File 'lib/formatron/cli/provision.rb', line 28

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