Module: Formatron::CLI::Generators::Instance

Defined in:
lib/formatron/cli/generators/instance.rb

Overview

CLI command for instance generator

Instance Method Summary collapse

Instance Method Details

#instance_action(c) ⇒ Object

rubocop:disable Metrics/MethodLength



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/formatron/cli/generators/instance.rb', line 87

def instance_action(c)
  c.action do |_args, options|
    directory = instance_directory options
    name = instance_name options, directory
    Formatron::Generators::Instance.generate(
      directory,
      name: name,
      instance_name: instance_instance_name(options, name),
      s3_bucket: instance_s3_bucket(options),
      bootstrap_configuration:
        instance_bootstrap_configuration(options),
      vpc: instance_vpc(options),
      subnet: instance_subnet(options),
      targets: instance_targets(options)
    )
  end
end

#instance_bootstrap_configuration(options) ⇒ Object



63
64
65
66
# File 'lib/formatron/cli/generators/instance.rb', line 63

def instance_bootstrap_configuration(options)
  options.bootstrap_configuration ||
    ask('Bootstrap configuration? ')
end

#instance_directory(options) ⇒ Object

rubocop:enable Metrics/MethodLength



41
42
43
44
45
# File 'lib/formatron/cli/generators/instance.rb', line 41

def instance_directory(options)
  options.directory || ask('Directory? ') do |q|
    q.default = Dir.pwd
  end
end

#instance_formatron_commandObject

rubocop:enable Metrics/MethodLength



106
107
108
109
110
111
112
113
114
# File 'lib/formatron/cli/generators/instance.rb', line 106

def instance_formatron_command
  command :'generate instance' do |c|
    c.syntax = 'formatron generate instance [options]'
    c.summary = 'Generate an instance configuration'
    c.description = 'Generate an instance configuration'
    instance_options c
    instance_action c
  end
end

#instance_instance_name(options, name) ⇒ Object



53
54
55
56
57
# File 'lib/formatron/cli/generators/instance.rb', line 53

def instance_instance_name(options, name)
  options.instance_name || ask('Instance Name? ') do |q|
    q.default = name
  end
end

#instance_name(options, directory) ⇒ Object



47
48
49
50
51
# File 'lib/formatron/cli/generators/instance.rb', line 47

def instance_name(options, directory)
  options.name || ask('Name? ') do |q|
    q.default = File.basename directory
  end
end

#instance_options(c) ⇒ Object

rubocop:disable Metrics/MethodLength



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
# File 'lib/formatron/cli/generators/instance.rb', line 9

def instance_options(c)
  c.option '-n', '--name STRING', 'The name for the configuration'
  c.option '-i', '--instance-name STRING', 'The name for the instance'
  c.option(
    '-s',
    '--s3-bucket STRING',
    'The S3 bucket to store encrypted configuration'
  )
  c.option(
    '-b',
    '--bootstrap-configuration STRING',
    'The name of the bootstrap configuration to depend on'
  )
  c.option(
    '-p',
    '--vpc STRING',
    'The name of the VPC to add the instance to'
  )
  c.option(
    '-u',
    '--subnet STRING',
    'The name of the subnet to add the instance to'
  )
  c.option(
    '-x',
    '--targets LIST',
    Array,
    'The targets (eg. production test)'
  )
end

#instance_s3_bucket(options) ⇒ Object



59
60
61
# File 'lib/formatron/cli/generators/instance.rb', line 59

def instance_s3_bucket(options)
  options.s3_bucket || ask('S3 Bucket? ')
end

#instance_subnet(options) ⇒ Object



74
75
76
77
78
# File 'lib/formatron/cli/generators/instance.rb', line 74

def instance_subnet(options)
  options.subnet || ask('Subnet? ') do |q|
    q.default = 'private'
  end
end

#instance_targets(options) ⇒ Object



80
81
82
83
84
# File 'lib/formatron/cli/generators/instance.rb', line 80

def instance_targets(options)
  options.targets || ask('Targets? ', Array) do |q|
    q.default = 'production test'
  end
end

#instance_vpc(options) ⇒ Object



68
69
70
71
72
# File 'lib/formatron/cli/generators/instance.rb', line 68

def instance_vpc(options)
  options.vpc || ask('VPC? ') do |q|
    q.default = 'vpc'
  end
end