#!/usr/bin/env ruby require 'thor' require_relative '../lib/convection/control/cloud' module Convection ## # Convection CLI ## class CLI < Thor class_option :cloudfile, :type => :string, :default => 'Cloudfile' def initialize(*args) super @cloud = Control::Cloud.new @cwd = Dir.getwd end desc 'converge STACK', 'Converge your cloud' def converge(stack = nil) @cloud.configure(File.absolute_path(options['cloudfile'], @cwd)) @cloud.converge(stack) do |event, errors| say_status(*event.to_thor) errors.each do |error| say "* #{ error.message }" error.backtrace.each { |b| say " #{ b }" } end unless errors.nil? end end desc 'diff', 'Show changes that will be applied by converge' option :verbose, :type => :boolean, :aliases => '--v', :desc => 'Show stack progress' option :'very-verbose', :type => :boolean, :aliases => '--vv', :desc => 'Show unchanged stacks' def diff @cloud.configure(File.absolute_path(options['cloudfile'], @cwd)) last_event = nil @cloud.diff do |d| if d.is_a? Model::Event if options[:'very-verbose'] say_status(*d.to_thor) elsif options[:verbose] say_status(*d.to_thor) if d.name == :compare end last_event = d elsif d.is_a? Model::Diff if !options[:'very-verbose'] && !options[:verbose] say_status(*last_event.to_thor) unless last_event.nil? last_event = nil end say_status(*d.to_thor) else say_status(*d.to_thor) end end end desc 'print STACK', 'Print the rendered template for STACK' def print(stack) @cloud.configure(File.absolute_path(options['cloudfile'], @cwd)) puts @cloud.stacks[stack].to_json(true) end desc 'validate STACK', 'Validate the rendered template for STACK' def validate(stack) @cloud.configure(File.absolute_path(options['cloudfile'], @cwd)) @cloud.stacks[stack].validate end end end Convection::CLI.start(ARGV)