Skip to content
Browse files

Handle no config_file with clean abort message, implement init command

  • Loading branch information...
1 parent 8e0ddd5 commit b5ca2df4c7dc42bfc3ca790a03ca1762d5ee799d @cldwalker cldwalker committed Apr 23, 2012
Showing with 18 additions and 7 deletions.
  1. +18 −7 lib/pairhost.rb
View
25 lib/pairhost.rb
@@ -2,10 +2,20 @@
require 'fog'
require 'thor'
require 'yaml'
+require 'fileutils'
module Pairhost
+ def self.config_file
+ @config_file ||= File.expand_path('~/.pairhost/config.yml')
+ end
+
def self.config
- @config ||= YAML.load(File.open(File.expand_path('~/.pairhost/config.yml')))
+ @config ||= begin
+ unless File.exists? config_file
+ abort "No pairhost config found. First run 'pairhost init'."
+ end
+ YAML.load_file config_file
+ end
end
def self.instance_id
@@ -16,7 +26,7 @@ def self.connection
return @connection if @connection
Fog.credentials = Fog.credentials.merge(
- :private_key_path => config['private_key_path'],
+ :private_key_path => config['private_key_path'],
)
@connection = Fog::Compute.new(
@@ -134,7 +144,7 @@ def list
Pairhost.connection.servers.each do |server|
puts server.tags['Name']
puts server.inspect
- puts
+ puts
puts
end
end
@@ -148,16 +158,17 @@ def initials
desc "init", "Setup your ~/.pairhost directory with default config"
def init
-
+ FileUtils.mkdir_p File.dirname(Pairhost.config_file)
+ FileUtils.cp(File.dirname(__FILE__) + '/../config.example.yml', Pairhost.config_file)
end
- private
-
+ private
+
def display_status(server)
puts "#{server.id}: #{server.tags['Name']}"
puts "State: #{server.state}"
puts server.dns_name if server.dns_name
end
end
-end
+end

0 comments on commit b5ca2df

Please sign in to comment.
Something went wrong with that request. Please try again.