Class: FlareUp::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/flare_up/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bailout(exit_code) ⇒ Object



51
52
53
# File 'lib/flare_up/cli.rb', line 51

def self.bailout(exit_code)
  exit(exit_code)
end

.env_validator(options, option_name, env_variable_name) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
# File 'lib/flare_up/cli.rb', line 45

def self.env_validator(options, option_name, env_variable_name)
  options[option_name] ||= ENVWrap.get(env_variable_name)
  return if options[option_name]
  raise ArgumentError, "One of either the --#{option_name} option or the ENV['#{env_variable_name}'] must be set"
end

Instance Method Details

#copy(data_source, endpoint, database_name, table_name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/flare_up/cli.rb', line 21

def copy(data_source, endpoint, database_name, table_name)
  boot_options = {
    :data_source => data_source,
    :redshift_endpoint => endpoint,
    :database => database_name,
    :table => table_name
  }
  options.each { |k, v| boot_options[k.to_sym] = v }

  begin
    CLI.env_validator(boot_options, :aws_access_key, 'AWS_ACCESS_KEY_ID')
    CLI.env_validator(boot_options, :aws_secret_key, 'AWS_SECRET_ACCESS_KEY')
    CLI.env_validator(boot_options, :redshift_username, 'REDSHIFT_USERNAME')
    CLI.env_validator(boot_options, :redshift_password, 'REDSHIFT_PASSWORD')
  rescue ArgumentError => e
    Emitter.error(e.message)
    CLI.bailout(1)
  end

  OptionStore.store_options(boot_options)

  Boot.boot
end