foreman 0.59.0 → 0.60.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/foreman/cli.rb CHANGED
@@ -75,10 +75,19 @@ class Foreman::CLI < Thor
75
75
 
76
76
  def run(*args)
77
77
  load_environment!
78
+
79
+ if File.exist?(procfile)
80
+ engine.load_procfile(procfile)
81
+ end
82
+
78
83
  pid = fork do
79
84
  begin
80
85
  engine.env.each { |k,v| ENV[k] = v }
81
- exec args.shelljoin
86
+ if args.size == 1 && process = engine.process(args.first)
87
+ process.exec(:env => engine.env)
88
+ else
89
+ exec args.shelljoin
90
+ end
82
91
  rescue Errno::EACCES
83
92
  error "not executable: #{args.first}"
84
93
  rescue Errno::ENOENT
@@ -21,6 +21,21 @@ class Foreman::Process
21
21
  @options[:env] ||= {}
22
22
  end
23
23
 
24
+ # Get environment-expanded command for a +Process+
25
+ #
26
+ # @param [Hash] custom_env ({}) Environment variables to merge with defaults
27
+ #
28
+ # @return [String] The expanded command
29
+ #
30
+ def expanded_command(custom_env={})
31
+ env = @options[:env].merge(custom_env)
32
+ expanded_command = command.dup
33
+ env.each do |key, val|
34
+ expanded_command.gsub!("$#{key}", val)
35
+ end
36
+ expanded_command
37
+ end
38
+
24
39
  # Run a +Process+
25
40
  #
26
41
  # @param [Hash] options
@@ -31,16 +46,12 @@ class Foreman::Process
31
46
  # @returns [Fixnum] pid The +pid+ of the process
32
47
  #
33
48
  def run(options={})
34
- env = options[:env] ? @options[:env].merge(options[:env]) : @options[:env]
49
+ env = @options[:env].merge(options[:env] || {})
35
50
  output = options[:output] || $stdout
36
51
 
37
52
  if Foreman.windows?
38
53
  Dir.chdir(cwd) do
39
- expanded_command = command.dup
40
- env.each do |key, val|
41
- expanded_command.gsub!("$#{key}", val)
42
- end
43
- Process.spawn env, expanded_command, :out => output, :err => output
54
+ Process.spawn env, expanded_command(env), :out => output, :err => output
44
55
  end
45
56
  elsif Foreman.jruby?
46
57
  require "posix/spawn"
@@ -52,7 +63,7 @@ class Foreman::Process
52
63
  $stderr.reopen output
53
64
  env.each { |k,v| ENV[k] = v }
54
65
  wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
55
- exec wrapped_command
66
+ Kernel.exec wrapped_command
56
67
  end
57
68
  else
58
69
  wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
@@ -60,6 +71,20 @@ class Foreman::Process
60
71
  end
61
72
  end
62
73
 
74
+ # Exec a +Process+
75
+ #
76
+ # @param [Hash] options
77
+ #
78
+ # @option options :env ({}) Environment variables to set for this execution
79
+ #
80
+ # @return Does not return
81
+ def exec(options={})
82
+ env = @options[:env].merge(options[:env] || {})
83
+ env.each { |k, v| ENV[k] = v }
84
+ Dir.chdir(cwd)
85
+ Kernel.exec expanded_command(env)
86
+ end
87
+
63
88
  # Send a signal to this +Process+
64
89
  #
65
90
  # @param [String] signal The signal to send
@@ -1,5 +1,5 @@
1
1
  module Foreman
2
2
 
3
- VERSION = "0.59.0"
3
+ VERSION = "0.60.0"
4
4
 
5
5
  end
@@ -73,6 +73,10 @@ describe "Foreman::CLI", :fakefs do
73
73
  forked_foreman("run #{resource_path("bin/env FOO")} -e #{resource_path(".env")}").should == "bar\n"
74
74
  end
75
75
 
76
+ it "can run a command from the Procfile" do
77
+ forked_foreman("run -f #{resource_path("Procfile")} test").should == "testing\n"
78
+ end
79
+
76
80
  it "exits with the same exit code as the command" do
77
81
  fork_and_get_exitstatus("run echo 1").should == 0
78
82
  fork_and_get_exitstatus("run date 'invalid_date'").should == 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.59.0
4
+ version: 0.60.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-15 00:00:00.000000000 Z
12
+ date: 2012-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &70328417187820 !ruby/object:Gem::Requirement
16
+ requirement: &70126785343520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.13.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70328417187820
24
+ version_requirements: *70126785343520
25
25
  description: Process manager for applications with multiple components
26
26
  email: ddollar@gmail.com
27
27
  executables: