Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
better handling of taps command line args to fix interaction with --c…
Browse files Browse the repository at this point in the history
…onfirm
  • Loading branch information
ddollar committed Nov 17, 2010
1 parent aaa772b commit 849194b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/heroku/commands/db.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'yaml'
require 'logger'
require 'uri'

module Heroku::Command
class Db < BaseWithApp
Expand Down Expand Up @@ -116,8 +117,9 @@ def parse_taps_opts

opts[:indexes_first] = !extract_option("--indexes-last")

opts[:database_url] = args.shift.strip rescue ''
if opts[:database_url] == ''
opts[:database_url] = args.detect { |a| URI.parse(a).host } rescue nil

unless opts[:database_url]
opts[:database_url] = parse_database_yml
display "Auto-detected local database: #{opts[:database_url]}" if opts[:database_url] != ''
end
Expand Down
15 changes: 15 additions & 0 deletions spec/commands/db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,20 @@ module Heroku::Command
opts = @db.send(:parse_taps_opts)
opts[:table_filter].should == "(^tags$|^countries$)"
end

it "handles both a url and a --confirm on the command line" do
@db.stub!(:args).and_return(["mysql://user:pass@host/db", "--confirm", "myapp"])
opts = { :database_url => 'mysql://user:pass@host/db', :default_chunksize => 1000, :indexes_first => true }
@db.should_receive(:taps_client).with(:pull, opts)
@db.pull
end

it "handles no url and --confirm on the command line" do
@db.stub!(:args).and_return(["--confirm", "myapp"])
opts = { :database_url => 'mysql://user:pass@host/db', :default_chunksize => 1000, :indexes_first => true }
@db.should_receive(:parse_database_yml).and_return("mysql://user:pass@host/db")
@db.should_receive(:taps_client).with(:pull, opts)
@db.pull
end
end
end

0 comments on commit 849194b

Please sign in to comment.