Class: Tacoma::Command

Inherits:
Thor
  • Object
show all
Includes:
CacheEnvironment, Thor::Actions
Defined in:
lib/tacoma/command.rb

Constant Summary collapse

TOOLS =
{ fog: '.fog',
boto: '.boto',
s3cfg: '.s3cfg',
route53: '.route53',
aws_credentials: '.aws/credentials' }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CacheEnvironment

#environment_cache_path, #read_environment_from_cache, #update_environment_to_cache

Class Method Details

.source_rootObject



161
162
163
# File 'lib/tacoma/command.rb', line 161

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#cd(environment) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/tacoma/command.rb', line 133

def cd(environment)
  return unless switch(environment)

  Dir.chdir `echo #{@repo}`.strip
  puts 'Welcome to the tacoma shell'
  shell = ENV['SHELL'].split('/').last
  options =
    case shell
    when 'zsh'
      ''
    else
      '--login'
    end
  system("#{shell} #{options}")
  Process.kill(:SIGQUIT, Process.getpgid(Process.ppid))
end

#currentObject



91
92
93
94
# File 'lib/tacoma/command.rb', line 91

def current
  puts Tool.current_environment
  true
end

#installObject



151
152
153
154
155
156
157
158
159
# File 'lib/tacoma/command.rb', line 151

def install
  if File.exist?(File.join(Dir.home, '.tacoma.yml'))
    puts "File ~/.tacoma.yml already present, won't overwrite"
  else
    template_path = build_template_path('tacoma.yml')
    new_path = File.join(Dir.home, '.tacoma.yml')
    template template_path, new_path
  end
end

#listObject



69
70
71
72
73
# File 'lib/tacoma/command.rb', line 69

def list
  Tool.config.each_key do |key|
    puts key
  end
end

#switch(environment) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/tacoma/command.rb', line 99

def switch(environment)
  if Tool.load_vars(environment)
    @aws_identity_file = Tool.aws_identity_file
    @aws_secret_access_key = Tool.aws_secret_access_key
    @aws_access_key_id = Tool.aws_access_key_id
    @region = Tool.region
    @repo = Tool.repo
    @s3cfg = Tool.s3cfg

    # set configurations for tools
    TOOLS.each do |tool, config_path|
      template_path = build_template_path(tool)
      file_path = File.join(Dir.home, config_path)
      template template_path, file_path, force: true
    end

    system("ssh-add #{@aws_identity_file}")
    if options[:'with-exports']
      puts "export AWS_SECRET_ACCESS_KEY=#{@aws_secret_access_key}"
      puts "export AWS_SECRET_KEY=#{@aws_secret_access_key}"
      puts "export AWS_ACCESS_KEY=#{@aws_access_key_id}"
      puts "export AWS_ACCESS_KEY_ID=#{@aws_access_key_id}"
      puts "export AWS_DEFAULT_REGION=#{@region}"
    end

    update_environment_to_cache(environment)

    true
  else
    false
  end
end

#versionObject



82
83
84
85
86
87
88
# File 'lib/tacoma/command.rb', line 82

def version
  puts "tacoma, version #{Tacoma::VERSION}"
  puts 'Configuration templates available for:'
  TOOLS.each do |tool, config_path|
    puts "   #{tool} => '~/#{config_path}'"
  end
end