Class: Mysqlknife::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mysqlknife/cli.rb', line 7

def initialize(*args)
  super

  @config     = Configs.instance
  @mysql      = MySQL.new
  @mysql_cmd  = Mysql::Command.new
  @mysql_sql  = Mysql::SQL.new
  @command    = Command.new
  @parameters = Parameters.new
  $DEBUG      = options[:verbose]
end

Instance Method Details

#command(conn = nil, tool = nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/mysqlknife/cli.rb', line 77

def command(conn = nil, tool = nil)
  @parameters.connection = conn
  @parameters.tool       = tool
  @parameters.connections
  @parameters.tools

  if @parameters.tool_selected
    @config.connection(conn)
    @config.mysql_host = @parameters.host

    @command.execute(@mysql_cmd.parse(@parameters.tool))
  end
end

#config(conn = nil) ⇒ Object



20
21
22
23
24
# File 'lib/mysqlknife/cli.rb', line 20

def config(conn = nil)
  @parameters.connection = conn
  @parameters.connections
  @parameters.connection_details
end

#console(conn = nil, database = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mysqlknife/cli.rb', line 31

def console(conn = nil, database = nil)
  @parameters.connection = conn
  @parameters.database   = database
  @parameters.connections
  @parameters.hosts

  if @parameters.host_selected
    @config.connection(conn)
    @config.mysql_host     = @parameters.host
    @config.mysql_database = database

    @command.execute(@mysql_cmd.console(options[:execute]))
  end
end

#describe(conn = nil, host = nil, database = nil, table = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mysqlknife/cli.rb', line 62

def describe(conn = nil, host = nil, database = nil, table = nil)
  @parameters.connection = conn
  @parameters.host       = host
  @parameters.connections
  @parameters.hosts

  if @parameters.host_selected
    @config.connection(conn)
    @config.mysql_host = @parameters.host

    @command.execute(@mysql_cmd.describe(database, table))
  end
end

#kill(conn = nil, host = nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/mysqlknife/cli.rb', line 107

def kill(conn = nil, host = nil)
  @parameters.connection = conn
  @parameters.host       = host
  @parameters.connections
  @parameters.hosts

  if @parameters.host_selected
    @config.connection(conn)
    @config.mysql_host = @parameters.host

    @kill       = Mysql::Kill.new
    @kill.where = options[:where]

    if options[:kill]
      @kill.clear
    else
      @kill.show
    end
  end
end

#lag(conn = nil, host = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mysqlknife/cli.rb', line 47

def lag(conn = nil, host = nil)
  @parameters.connection = conn
  @parameters.host       = host
  @parameters.connections
  @parameters.slaves

  if @parameters.slave_selected
    @config.connection(conn)
    @config.mysql_host = @parameters.host

    @command.execute(@mysql_cmd.console(@mysql_sql.replica_lag))
  end
end

#skip(conn = nil, host = nil) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/mysqlknife/cli.rb', line 129

def skip(conn = nil, host = nil)
  @parameters.connection = conn
  @parameters.host       = host
  @parameters.connections
  @parameters.slaves

  if @parameters.slave_selected
    @config.connection(conn)
    @config.mysql_host = @parameters.host

    @replica = Mysql::Replica.new
    @replica.skip
  end
end

#versionObject



145
146
147
# File 'lib/mysqlknife/cli.rb', line 145

def version
  puts Mysqlknife::VERSION
end