Class: Opsup::CLI::OptionBuilder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/opsup/cli.rb

Constant Summary collapse

DEFAULT_OPSWORKS_REGION =
'ap-northeast-1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.createObject



72
73
74
# File 'lib/opsup/cli.rb', line 72

def self.create
  new
end

Instance Method Details

#define_options(parser) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/opsup/cli.rb', line 79

def define_options(parser)
  parser.tap do |p|
    p.on('-s', '--stack STACK_NAME', 'target stack name')
    p.on('-m', '--mode MODE', Opsup::Config::MODES.join(' | ').to_s)
    p.on('--aws-cred KEY_ID,SECRET_KEY', 'AWS credentials')
    p.on('--opsworks-region REGION', "default: #{DEFAULT_OPSWORKS_REGION}")
    p.on('-d', '--dryrun')
  end
end

#generate_config(options) ⇒ Object

Raises:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/opsup/cli.rb', line 90

def generate_config(options)
  %w[stack aws-cred].each do |key|
    raise Opsup::Error, "missing required option: --#{key}" unless options[key.to_sym]
  end

  aws_key_id, aws_secret = options[:"aws-cred"].split(',')
  if aws_key_id.nil? || aws_secret.nil?
    raise Opsup::Error, "aws-cred must be 'key_id,secret_key' format"
  end

  mode = options[:mode]&.to_sym
  raise Opsup::Error, "invalid mode: #{mode}" if mode && !Opsup::Config::MODES.include?(mode)

  Opsup::Config.new(
    stack_name: options[:stack],
    aws_access_key_id: aws_key_id,
    aws_secret_access_key: aws_secret,
    opsworks_region: options[:"opsworks-region"] || DEFAULT_OPSWORKS_REGION,
    running_mode: mode,
    dryrun: options[:dryrun] || false,
  )
end