Module: SimpleDeploy::CLI::Shared

Included in:
Attributes, Clone, Create, Deploy, Destroy, Environments, Events, Execute, Instances, List, Outputs, Parameters, Protect, Resources, Status, Template, Update
Defined in:
lib/simple_deploy/cli/shared.rb

Instance Method Summary collapse

Instance Method Details

#command_nameObject



53
54
55
# File 'lib/simple_deploy/cli/shared.rb', line 53

def command_name
  self.class.name.split('::').last.downcase
end

#parse_attributes(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/simple_deploy/cli/shared.rb', line 6

def parse_attributes(args)
  attributes = args[:attributes]
  attrs      = []

  attributes.each do |attribs|
    key   = attribs.split('=').first.gsub(/\s+/, "")
    value = attribs.gsub(/^.+?=/, '')
    SimpleDeploy.logger.info "Read #{key}=#{value}"
    attrs << { key => value }
  end
  attrs
end

#rescue_exceptions_and_exitObject



57
58
59
60
61
# File 'lib/simple_deploy/cli/shared.rb', line 57

def rescue_exceptions_and_exit
  yield
rescue SimpleDeploy::Exceptions::Base
  exit 1
end

#valid_options?(args) ⇒ Boolean

Returns:

  • (Boolean)


19
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
51
# File 'lib/simple_deploy/cli/shared.rb', line 19

def valid_options?(args)
  provided = args[:provided]
  required = args[:required]

  if provided[:environment] && provided[:read_from_env]
    SimpleDeploy.logger.error "You cannot specify both --environment and --read-from-env"
    exit 1
  end

  if required.include?(:environment) && required.include?(:read_from_env)
    if !provided.include?(:environment) && !provided.include?(:read_from_env)
      msg = "Either '--environment' or '--read-from-env' is required but not specified"
      SimpleDeploy.logger.error msg
      exit 1
    end
  end

  required.reject { |i| [:environment, :read_from_env].include? i }.each do |opt|
    unless provided[opt]
      SimpleDeploy.logger.error "Option '#{opt} (-#{opt[0]})' required but not specified."
      exit 1
    end
  end

  validate_credential_env_vars if provided[:read_from_env]

  if provided[:environment]
    unless SimpleDeploy.environments.keys.include? provided[:environment]
      SimpleDeploy.logger.error "Environment '#{provided[:environment]}' does not exist."
      exit 1
    end
  end
end