Class: Pasqual::CLI
- Inherits:
-
Thor
- Object
- Thor
- Pasqual::CLI
- Defined in:
- lib/pasqual/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create(url = nil) ⇒ Object
- #drop(url = nil) ⇒ Object
- #file(path, url = nil) ⇒ Object
- #poll(url = nil) ⇒ Object
- #psql(*cmd_args) ⇒ Object
- #reset(path = nil, url = nil) ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
7 8 9 |
# File 'lib/pasqual/cli.rb', line 7 def self.exit_on_failure? true end |
Instance Method Details
#create(url = nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/pasqual/cli.rb', line 12 def create(url = nil) puts "Creating #{pasqual(url).name}" pasqual(url).createdb rescue Pasqual::Createdb::AlreadyExists puts "#{pasqual(url).name} already exists, skipped creation" end |
#drop(url = nil) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/pasqual/cli.rb', line 20 def drop(url = nil) puts "Dropping #{pasqual(url).name}" pasqual(url).dropdb rescue Pasqual::Dropdb::Failed puts "Could not drop #{pasqual(url).name}, skipped" end |
#file(path, url = nil) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/pasqual/cli.rb', line 73 def file(path, url = nil) puts "Structuring #{pasqual(url).name}" pasqual(url).pipe_sql path rescue Errno::EPIPE puts "#{pasqual(url).name} doesn't exist, skipped structure" end |
#poll(url = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pasqual/cli.rb', line 28 def poll(url = nil) say "Waiting for Postgres to come available" if attempt_connect(url) say "Connected!" exit 0 else say "Failed to connect" exit 1 end end |
#psql(*cmd_args) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pasqual/cli.rb', line 47 def psql(*cmd_args) url = nil sql_args = [] cmd_args.each do |arg| if arg =~ /postgres:/ url = arg else sql_args << arg end end db = pasqual(url) args = Pasqual::Arglist. args(db.username, db.password, db.host, db.port, db.name) if sql_args.any? args << '-c' args += sql_args.map(&:inspect) puts "Executing in #{db.name}: #{sql_args.inspect}" else cmd = "psql #{args.join(' ')}" end puts "Running #{cmd}" Kernel.exec({ 'PGPASSWORD' => db.password }, "psql #{args.join(' ')}") end |
#reset(path = nil, url = nil) ⇒ Object
40 41 42 43 44 |
# File 'lib/pasqual/cli.rb', line 40 def reset(path = nil, url = nil) drop(url) create(url) file(path, url) if path end |