Class: Mycmd::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/mycmd/cli.rb

Instance Method Summary collapse

Instance Method Details

#consoleObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mycmd/cli.rb', line 13

def console
  raise "mysql not found" unless system("which mysql > /dev/null")
  conf = Configuration.new
  cmd = conf.to_hash.inject(["mysql"]) do |c,(k,v)|
    case k
    when :host then c << "-h#{v}"
    when :port then c << "-P#{v}"
    when :username then c << "-u#{v}"
    when :password then c << "-p#{v}"
    when :database then c << v
    end
  end

  system(cmd.join(" "))
end

#query(sql) ⇒ Object



30
31
32
33
34
# File 'lib/mycmd/cli.rb', line 30

def query(sql)
  client = Configuration.connect
  printer = Printer.new(client.query(sql), true)
  printer.print
end