Module: Lambit::Commands::Common

Defined in:
lib/lambit/commands/common.rb

Defined Under Namespace

Classes: Base, CreateWorkspaceCommand

Class Method Summary collapse

Class Method Details

.handler_for(cmd) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/lambit/commands/common.rb', line 26

def self.handler_for(cmd)
  if @handlers
    @handlers[normalize_cmd(cmd)]
  else
    raise 'Uh Oh!'
  end
end

.normalize_cmd(cmd) ⇒ Object



22
23
24
# File 'lib/lambit/commands/common.rb', line 22

def self.normalize_cmd(cmd)
  cmd.to_s.downcase
end

.register_handler_for(cmd, handler = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/lambit/commands/common.rb', line 34

def self.register_handler_for(cmd, handler=nil)
  normalized_cmd = normalize_cmd(cmd)
  handler        = self.const_get(normalized_cmd.classify) if handler.nil?

  @handlers ||= {}
  @handlers[normalized_cmd] = handler
end

.run(cmd, opts, args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/lambit/commands/common.rb', line 9

def self.run(cmd, opts, args)
  handler            = handler_for cmd
  output, exitstatus = handler.run opts, args

  # Send Subcommand output to STDOUT if :debug
  if Lambit.is_debug?
    puts output unless output.nil? || output.empty?
  end

  # Return exit status
  exitstatus
end