lib/gaptool_client/commands.rb in gaptool-client-0.8.0.pre.beta vs lib/gaptool_client/commands.rb in gaptool-client-0.8.0.pre.beta1

- old
+ new

@@ -26,19 +26,17 @@ def execute no_terminate = no_terminate? ? true : nil res = Gaptool::API.client.addnode(zone, type, role, environment, nil, security_group, ami, chef_repo, chef_branch, chef_runlist, no_terminate) - if res['result'] == 'error' - puts Rainbow(res['message']).red - exit 1 - end - - puts "#{Rainbow('Successfully init instance').green} #{Rainbow(res['instance']).blue}:" - res.select { |k, _| k != 'instance' && k != 'secret' }.sort.each do |k, v| - puts "- #{k}: #{Rainbow(v).blue}" - end + Gaptool::Helpers.error(res['message']) if res['result'] == 'error' + res.merge( + 'role' => role, + 'environment' => environment + ) + res.delete('secret') + Gaptool::Helpers.info([res], false, false) end end class TerminateCommand < Clamp::Command option ['-i', '--instance'], 'INSTANCE', 'Instance ID, e.g. i-12345678', required: true @@ -50,25 +48,31 @@ node = Gaptool::API.client.getonenode(instance) nodes = [node] Gaptool::Helpers.info(nodes, false, false) zone = node['zone'][0..-2] if node['environment'] != environment || node['role'] != role - puts Rainbow("'#{node['role']}-#{node['environment']}' do not match provided value (#{role}-#{environment})").red - exit 1 + Gaptool::Helpers.error("'#{node['role']}-#{node['environment']}' do not match provided value (#{role}-#{environment})") end - if node['terminate'] == 'false' - puts Rainbow('"terminate" command is disabled for this instance').red - exit 2 + if node['terminable'] == false + puts Rainbow('"terminate" command is disabled for this instance').yellow + puts 'To terminate the instance, set it as terminable first running:' + puts Rainbow("gt set -k terminable -v true -i #{instance}").cyan + puts + Gaptool::Helpers.error("Cannot terminate instance #{instance}", + code: 2) end print Rainbow('Terminate instance? [type yes to confirm]: ').green res = $stdin.gets.chomp return 0 unless res.downcase == 'yes' puts "Terminating instance #{node['role']}:#{node['environment']}:#{node['instance']} in region #{zone}" begin - Gaptool::API.client.terminatenode(instance, zone) - rescue - puts Rainbow('Cannot terminate instance').red + res = Gaptool::API.client.terminatenode(instance, zone) + rescue => e + Gaptool::Helpers.error("Cannot terminate instance: #{e}") end + Gaptool::Helpers.error("Cannot terminate instance: #{res['message']}") \ + if res['result'] == 'error' + puts Rainbow("Successfully terminated instance #{instance}").green end end class RuncmdCommand < Clamp::Command option ['-r', '--role'], 'ROLE', 'Instance role'