class Pushapp::Commands

Attributes

logger[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/pushapp/commands.rb, line 11
def initialize(options = {})
  @options = options
  @logger = Pushapp::Logger.new
end
run(command, options = {}) click to toggle source
# File lib/pushapp/commands.rb, line 7
def self.run(command, options = {})
  self.new(options.merge({ command: command })).send(command)
end

Public Instance Methods

exec() click to toggle source
# File lib/pushapp/commands.rb, line 79
def exec
  if remote
    cmd = (@options[:args] || []).join(' ')
    if cmd.empty?
      puts 'Usage: pushapp exec remote COMMAND'
    else
      begin
        remote.env_run "bundle exec #{cmd}"
      rescue Exception => e
        puts e.message
      end
    end
  else
    logger.error 'Remote not found'
  end
end
init() click to toggle source
# File lib/pushapp/commands.rb, line 16
def init
  logger.info "Creating an example config file in #{Pushapp::DEFAULT_CONFIG_LOCATION}"
  logger.info 'Customize it to your needs'
  create_config_directory
  write_config_file
end
list_remotes() click to toggle source
# File lib/pushapp/commands.rb, line 28
def list_remotes
  logger.info 'Known remotes:'
  remotes_table = config.remotes.map {|r| [r.full_name, r.location, r.env]}
  remotes_table.unshift ['Full Name', 'Location', 'ENV']
  logger.shell.print_table(remotes_table)
end
setup() click to toggle source
# File lib/pushapp/commands.rb, line 35
def setup
  logger.info 'Setting up remotes'
  remotes.each { |r| r.setup! }
  update_refs
end
ssh() click to toggle source
# File lib/pushapp/commands.rb, line 71
def ssh
  if remote
    remote.ssh!
  else
    logger.error 'Remote not found'
  end
end
tasks() click to toggle source
# File lib/pushapp/commands.rb, line 41
def tasks
  remotes_list = remotes.empty? ? config.remotes : remotes
  remotes_list.each do |r|
    puts "REMOTE: #{r.full_name}"
    r.tasks.keys.each do |event|
      puts "    EVENT: #{event}"
      r.tasks[event].each do |task|
        puts "        #{task.inspect}"
      end
    end
  end
end
trigger() click to toggle source
# File lib/pushapp/commands.rb, line 54
def trigger
  event = @options[:event]
  local = @options[:local]
  if local
    $stdout.sync = $stderr.sync = true
    logger.info "STARTING TASKS ON EVENT #{event}"
    remotes.each do |r|
      r.tasks_on(event).each do |t|
        logger.info "task: #{t.inspect}"
        Pushapp::Pipe.run(t)
      end
    end
  else
    remotes.each {|r| r.env_run "bundle exec pushapp trigger #{event} #{r.full_name} -l true"}
  end
end
update_refs() click to toggle source
# File lib/pushapp/commands.rb, line 23
def update_refs
  logger.info 'Updating .git/config. Setting up refs to all remotes'
  Pushapp::Git.new.update_tracked_repos(config)
end

Private Instance Methods

config() click to toggle source
# File lib/pushapp/commands.rb, line 106
def config
  @config ||= Pushapp::Config.parse(@config_file)
end
create_config_directory() click to toggle source
# File lib/pushapp/commands.rb, line 110
def create_config_directory
  Dir.mkdir 'config' unless File.exists? 'config'
end
remote() click to toggle source
# File lib/pushapp/commands.rb, line 98
def remote
  @remote ||= config.remotes_named_by(@options[:remote]).first
end
remotes() click to toggle source
# File lib/pushapp/commands.rb, line 102
def remotes
  @remotes ||= config.remotes_matched(@options[:remotes])
end
write_config_file() click to toggle source
# File lib/pushapp/commands.rb, line 114
def write_config_file
  config = ERB.new(File.read("#{Pushapp::TEMPLATE_ROOT}/config.rb.erb")).result
  File.open(Pushapp::DEFAULT_CONFIG_LOCATION,"wb") { |f| f.puts config }
end