Class: Mysqlknife::Mysql::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/mysqlknife/mysql/command.rb

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



6
7
8
# File 'lib/mysqlknife/mysql/command.rb', line 6

def initialize
  @cnf = Configs.instance
end

Instance Method Details

#checkObject



10
11
12
13
# File 'lib/mysqlknife/mysql/command.rb', line 10

def check
  find_executable('mysql')
  find_executable('mysqlshow')
end

#console(sentence = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mysqlknife/mysql/command.rb', line 40

def console(sentence = nil)
  %W[mysql
     -h #{@cnf.mysql_host}
     -P #{@cnf.mysql_port}
     -u #{@cnf.mysql_username}
     #{password(@cnf.mysql_password)}
     --prompt='#{prompt}[\\d]> '
     #{@cnf.mysql_database}
     #{execute(sentence)}
     ].join(' ')
end

#describe(*args) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/mysqlknife/mysql/command.rb', line 52

def describe(*args)
  %W[mysqlshow
     -h #{@cnf.mysql_host}
     -P #{@cnf.mysql_port}
     -u #{@cnf.mysql_username}
     #{password(@cnf.mysql_password)}
     --keys
     #{args.join(' ')}].join(' ')
end

#execute(sentence) ⇒ Object



32
33
34
# File 'lib/mysqlknife/mysql/command.rb', line 32

def execute(sentence)
  "--execute='#{sentence}'" unless sentence.nil?
end

#parse(command) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/mysqlknife/mysql/command.rb', line 15

def parse(command)
  host     = @cnf.mysql_host
  port     = @cnf.mysql_port
  username = @cnf.mysql_username
  password = password(@cnf.mysql_password)

  eval("\"#{command}\"")
end

#password(password) ⇒ Object



36
37
38
# File 'lib/mysqlknife/mysql/command.rb', line 36

def password(password)
  "-p#{password}" unless password.nil?
end

#promptObject



24
25
26
27
28
29
30
# File 'lib/mysqlknife/mysql/command.rb', line 24

def prompt
  if !!(@cnf.mysql_host =~ Resolv::IPv4::Regex)
    @cnf.name
  else
    @cnf.mysql_host.partition('.').first
  end
end