Module: Crucigrama::CLI

Defined in:
lib/crucigrama/cli.rb

Defined Under Namespace

Classes: Generate, Print

Constant Summary collapse

@@commands =
{}
@@cli_command =
nil

Class Method Summary collapse

Class Method Details

.cli_commandObject



7
8
9
# File 'lib/crucigrama/cli.rb', line 7

def self.cli_command
  @@cli_command
end

.cli_command=(value) ⇒ Object



11
12
13
# File 'lib/crucigrama/cli.rb', line 11

def self.cli_command=(value)
  @@cli_command = value
end

.deregister(command) ⇒ Object



19
20
21
# File 'lib/crucigrama/cli.rb', line 19

def self.deregister(command)
  @@commands.delete(command)
end

.register(command, command_handler, description) ⇒ Object



15
16
17
# File 'lib/crucigrama/cli.rb', line 15

def self.register(command, command_handler, description)
  @@commands[command] = {:command_handler => command_handler, :description => description}
end

.run(*args) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/crucigrama/cli.rb', line 23

def self.run(*args)
  command = args.delete_at(0)
  if command = @@commands[command]
    command[:command_handler].new(*args)
  else
    show_banner
  end
end

.show_bannerObject



32
33
34
35
36
37
38
# File 'lib/crucigrama/cli.rb', line 32

def self.show_banner
  puts "\nUsage: #{self.cli_command} command [options]\n
where command can be one of the following:\n
#{@@commands.collect do |key, value| 
    "#{key}: #{value[:description]}"
  end.join("\n")}\n\n"
end