Class: Foreman::CLI

Inherits:
Thor
  • Object
show all
Includes:
Helpers
Defined in:
lib/foreman/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#classify, #constantize

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/foreman/cli.rb', line 30

def exit_on_failure?
  true
end

.is_thor_reserved_word?(word, type) ⇒ Boolean

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

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/foreman/cli.rb', line 35

def is_thor_reserved_word?(word, type)
  return false if word == "run"
  super
end

Instance Method Details

#checkObject



75
76
77
78
79
80
81
# File 'lib/foreman/cli.rb', line 75

def check
  check_procfile!
  engine.load_procfile(procfile)
  puts "valid procfile detected (#{engine.process_names.join(', ')})"
rescue Foreman::Procfile::EmptyFileError
  error "no processes defined"
end

#export(format, location = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/foreman/cli.rb', line 63

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, Foreman::Procfile::EmptyFileError => ex
  error ex.message
end

#run(*args) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/foreman/cli.rb', line 88

def run(*args)
  load_environment!

  if File.file?(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 || 0
rescue Interrupt
rescue Foreman::Procfile::EmptyFileError
  error "no processes defined"
end

#start(process = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/foreman/cli.rb', line 41

def start(process=nil)
  check_procfile!
  load_environment!
  engine.load_procfile(procfile)
  engine.options[:formation] = "#{process}=1" if process
  engine.start
rescue Foreman::Procfile::EmptyFileError
  error "no processes defined"
end

#versionObject



121
122
123
# File 'lib/foreman/cli.rb', line 121

def version
  puts Foreman::VERSION
end