Sha256: a0fcf61f45308efcb6fc5b071f9e3276e2586c0cd8b6ec2e2da4bf1308ba80dd

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

require 'rubygems'
require 'aerosol'
require 'clamp'

class Aerosol::AbstractCommand < Clamp::Command
  option ['-f', '--file'], 'FILE', 'aerosol file to read', :default => 'aerosol.rb', :attribute_name => :file

  def execute
    if File.exist?(file)
      Aerosol.load_file = file
    else
      raise 'Could not find an aerosol file!'
    end
  end
end

class Aerosol::DeployCommand < Aerosol::AbstractCommand
  parameter 'DEPLOY', 'the deploy to run (can also be an environment name) for', :attribute_name => :deploy_name

  def execute
    super

    if Aerosol.deploy(deploy_name.to_sym)
      Rake::Task["aerosol:#{deploy_name}:all"].invoke
    elsif Aerosol.env(deploy_name.to_sym)
      Rake::Task["aerosol:env:#{deploy_name}"].invoke
    end
  end
end

class Aerosol::SshCommand < Aerosol::AbstractCommand
  option ['-r', '--run'], :flag, 'run first ssh command', :attribute_name => :run_first
  parameter 'DEPLOY', 'the deploy to list commands for', :attribute_name => :deploy_name

  def execute
    super
    if deploy = Aerosol.deploy(deploy_name.to_sym)
      ssh_commands = deploy.generate_ssh_commands
      raise 'No instances to ssh too!' if ssh_commands.empty?

      ssh_commands.each do |ssh_command|
        puts ssh_command
      end

      if run_first?
        system(ssh_commands.first)
      end
    end
  end
end

class Aerosol::Cli < Aerosol::AbstractCommand
  subcommand ['ssh', 's'], 'Print ssh commands for latest running instances', Aerosol::SshCommand
  subcommand ['deploy', 'd'], 'Run a deploy', Aerosol::DeployCommand
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
aerosol-1.10.0 lib/aerosol/cli.rb
aerosol-1.9.2 lib/aerosol/cli.rb
aerosol-1.9.1 lib/aerosol/cli.rb
aerosol-1.9.0 lib/aerosol/cli.rb
aerosol-1.8.0 lib/aerosol/cli.rb
aerosol-1.7.1 lib/aerosol/cli.rb
aerosol-1.7.0 lib/aerosol/cli.rb
aerosol-1.7.0.pre.1 lib/aerosol/cli.rb