Module: Hivonic::Commands
- Defined in:
- lib/hivonic/commands.rb
Defined Under Namespace
Classes: CleanupQueryCommand, CleanupTables, CleanupViews, DropTable, DropView, HiveQueryCommand, ListTables, Subcommand
Class Method Summary
collapse
Class Method Details
.handler_for(cmd) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/hivonic/commands.rb', line 21
def self.handler_for(cmd)
if @handlers
@handlers[normalize_cmd(cmd)]
else
raise 'Uh Oh!'
end
end
|
.normalize_cmd(cmd) ⇒ Object
17
18
19
|
# File 'lib/hivonic/commands.rb', line 17
def self.normalize_cmd(cmd)
cmd.to_s.downcase
end
|
.register_handler_for(cmd, handler = nil) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/hivonic/commands.rb', line 29
def self.register_handler_for(cmd, handler=nil)
normalized_cmd = normalize_cmd(cmd)
handler = Hivonic::Commands.const_get(normalized_cmd.classify) if handler.nil?
@handlers ||= {}
@handlers[normalized_cmd] = handler
end
|
.run(cmd, opts, args) ⇒ Object
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/hivonic/commands.rb', line 6
def self.run(cmd, opts, args)
handler = handler_for cmd
output, exitstatus = handler.run opts, args
puts output unless output.nil? || output.empty?
exitstatus
end
|