class Foreman::CLI

Public Class Methods

is_thor_reserved_word?(word, type) click to toggle source

Hackery. Take the run method away from Thor so that we can redefine it.

Calls superclass method
# File lib/foreman/cli.rb, line 30
def is_thor_reserved_word?(word, type)
  return false if word == "run"
  super
end

Public Instance Methods

check() click to toggle source
# File lib/foreman/cli.rb, line 67
def check
  check_procfile!
  engine.load_procfile(procfile)
  error "no processes defined" unless engine.processes.length > 0
  puts "valid procfile detected (#{engine.process_names.join(', ')})"
end
engine() click to toggle source
# File lib/foreman/cli.rb, line 115
def engine
  @engine ||= begin
    engine_class = Foreman::Engine::CLI
    engine = engine_class.new(options)
    engine
  end
end
export(format, location=nil) click to toggle source
# File lib/foreman/cli.rb, line 55
def export(format, location=nil)
  check_procfile!
  load_environment!
  engine.load_procfile(procfile)
  formatter = Foreman::Export.formatter(format)
  formatter.new(location, engine, options).export
rescue Foreman::Export::Exception => ex
  error ex.message
end
run(*args) click to toggle source
# File lib/foreman/cli.rb, line 79
def run(*args)
  load_environment!

  if File.exist?(procfile)
    engine.load_procfile(procfile)
  end

  pid = fork do
    begin
      engine.env.each { |k,v| ENV[k] = v }
      if args.size == 1 && process = engine.process(args.first)
        process.exec(:env => engine.env)
      else
        exec args.shelljoin
      end
    rescue Errno::EACCES
      error "not executable: #{args.first}"
    rescue Errno::ENOENT
      error "command not found: #{args.first}"
    end
  end
  trap("INT") do
    Process.kill(:INT, pid)
  end
  Process.wait(pid)
  exit $?.exitstatus
rescue Interrupt
end
start(process=nil) click to toggle source
# File lib/foreman/cli.rb, line 36
def start(process=nil)
  check_procfile!
  load_environment!
  engine.load_procfile(procfile)
  engine.options[:formation] = "#{process}=1" if process
  engine.start
end
version() click to toggle source
# File lib/foreman/cli.rb, line 110
def version
  puts Foreman::VERSION
end

Private Instance Methods

check_procfile!() click to toggle source
# File lib/foreman/cli.rb, line 131
def check_procfile!
  error("#{procfile} does not exist.") unless File.exist?(procfile)
end
error(message) click to toggle source
# File lib/foreman/cli.rb, line 126
def error(message)
  puts "ERROR: #{message}"
  exit 1
end
load_environment!() click to toggle source
# File lib/foreman/cli.rb, line 135
def load_environment!
  if options[:env]
    options[:env].split(",").each do |file|
      engine.load_env file
    end
  else
    default_env = File.join(engine.root, ".env")
    engine.load_env default_env if File.exists?(default_env)
  end
end
options() click to toggle source
Calls superclass method
# File lib/foreman/cli.rb, line 154
def options
  original_options = super
  return original_options unless File.exists?(".foreman")
  defaults = ::YAML::load_file(".foreman") || {}
  Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
end
procfile() click to toggle source
# File lib/foreman/cli.rb, line 146
def procfile
  case
    when options[:procfile] then options[:procfile]
    when options[:root]     then File.expand_path(File.join(options[:root], "Procfile"))
    else "Procfile"
  end
end