Skip to content

Commit

Permalink
Merge pull request #60 from heroku/fixes
Browse files Browse the repository at this point in the history
4.0.9: make default options overridable in App#run
  • Loading branch information
schneems authored May 22, 2019
2 parents 12815a5 + f05c60c commit fbb7f29
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## HEAD

## 4.0.9

- Allow overriding of all App#run options, including option removal (by passing `Hatchet::App::SkipDefaultOption` as the value)

## 4.0.8

- Fix `hatchet destroy` calling class from wrong module
Expand Down
10 changes: 7 additions & 3 deletions lib/hatchet/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def initialize(app, output)
end
end

SkipDefaultOption = Object.new

def initialize(repo_name,
stack: "",
name: default_name,
Expand Down Expand Up @@ -108,12 +110,14 @@ def add_database(plan_name = 'heroku-postgresql:dev', match_val = "HEROKU_POSTGR
# but programatically and with more control
def run(cmd_type, command = nil, options = {}, &block)
command = cmd_type.to_s if command.nil?
heroku_options = (options.delete(:heroku) || {}).map do |k,v|
default_options = { "app" => name, "exit-code" => nil }
heroku_options = (default_options.merge(options.delete(:heroku) || {})).map do |k,v|
next if v == Hatchet::App::SkipDefaultOption # for forcefully removing e.g. --exit-code, a user can pass this
arg = "--#{k.to_s.shellescape}"
arg << "=#{v.to_s.shellescape}" unless v.nil?
arg << "=#{v.to_s.shellescape}" unless v.nil? # nil means we include the option without an argument
arg
end.join(" ")
heroku_command = "heroku run -a #{name} #{heroku_options} --exit-code -- #{command}"
heroku_command = "heroku run #{heroku_options} -- #{command}"
bundle_exec do
if block_given?
ReplRunner.new(cmd_type, heroku_command, options).run(&block)
Expand Down
2 changes: 1 addition & 1 deletion lib/hatchet/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Hatchet
VERSION = "4.0.8"
VERSION = "4.0.9"
end
10 changes: 10 additions & 0 deletions test/hatchet/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ def test_run
app.deploy do
assert_match /ls: cannot access 'foo bar #baz': No such file or directory\s+Gemfile/, app.run("ls -a Gemfile 'foo bar #baz'")
assert (0 != $?.exitstatus) # $? is from the app.run use of backticks
sleep(3)
app.run("ls erpderp", nil, { :heroku => { "exit-code" => Hatchet::App::SkipDefaultOption } } )
assert (0 == $?.exitstatus) # $? is from the app.run use of backticks, but we asked the CLI not to return the program exit status by skipping the default "exit-code" option
sleep(3)
app.run("ls erpderp", nil, { :heroku => { "no-tty" => nil } } )
assert (0 != $?.exitstatus) # $? is from the app.run use of backticks
sleep(3)
assert_match /ohai world/, app.run('echo \$HELLO \$NAME', nil, { :heroku => { "env" => "HELLO=ohai;NAME=world" } } )
sleep(3)
refute_match /ohai world/, app.run('echo \$HELLO \$NAME', nil, { :heroku => { "env" => "" } } )
end
end
end

0 comments on commit fbb7f29

Please sign in to comment.