Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ USAGE: subcontract [options] -- executable
-c, --choose-env ENV run in either a specified RBENV, RVM or CHRUBY, whichever is present
-d, --chdir PATH chdir to PATH before starting process
-s, --signal SIGNAL signal to send to process to kill it, default TERM
-e, --env VAR=value additional environment variable to be set on executable context
```

An example Procfile tells the story
Expand Down Expand Up @@ -67,6 +68,12 @@ If you have team members using both rvm and rbenv on a project then use --choose
mixed_env_manager_app: bundle exec subcontract --choose-env . --chdir ~/mixed_env_manager_app -- bundle exec rails server -p 3001
```

You can pass multiple environment variables to be passed along to the executable.

```
rbenv_app: bundle exec subcontract --rbenv 'ree-1.8.7-2012.02' --chdir ~/rbenv_app --env FOO=bar --env BAR=foo -- bundle exec rails server -p 3001
```


### Contributions
* Fork the project
Expand Down
4 changes: 4 additions & 0 deletions lib/subcontractor/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def find_child_pids(pids)

def parse_options(argv)
options = {}
options[:env] = []
parser = OptionParser.new do |opt|
opt.banner = "USAGE: subcontract [options] -- executable"
opt.on("-r", "--rvm RVM", "run in a specific RVM") do |rvm|
Expand All @@ -96,6 +97,9 @@ def parse_options(argv)
opt.on("-s", "--signal SIGNAL", "signal to send to process to kill it, default TERM") do |signal|
options[:signal] = signal
end
opt.on("-e", "--env VAR=value", "additional environment variable to be set on executable context") do |env|
options[:env] << "env #{env}"
end
end

parser.parse! argv
Expand Down
2 changes: 1 addition & 1 deletion lib/subcontractor/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def build
@parts.unshift("chruby-exec #{_env_specifier(:chruby)} --")
end

@parts.join(" ")
(@options[:env] + @parts).join(" ")
end

def _use_command?(command)
Expand Down
22 changes: 22 additions & 0 deletions spec/subcontractor/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,27 @@
Subcontractor::CLI.new.run
end
end

context "with --env" do
it "specifies custom env variable" do
ARGV = ["--env", "FOO=bar", "test"]
SafePty.should_receive(:spawn).with("env FOO=bar test")
Subcontractor::CLI.new.run
end

it "specifies custom env variables if many where passed" do
ARGV = ["--env", "FOO=bar", "--env", "BAR=foo", "test"]
SafePty.should_receive(:spawn).with("env FOO=bar env BAR=foo test")
Subcontractor::CLI.new.run
end
end

context "with --env and --rbenv" do
it "specifies custom env variables if many where passed" do
ARGV = ["--rbenv", "1.9.3", "--env", "FOO=bar", "--env", "BAR=foo", "test"]
SafePty.should_receive(:spawn).with("env FOO=bar env BAR=foo env RBENV_VERSION=1.9.3 rbenv exec test")
Subcontractor::CLI.new.run
end
end
end
end