Class: Ruwi::Cli::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/ruwi/cli/command.rb,
lib/ruwi/cli/command/dev.rb,
lib/ruwi/cli/command/base.rb,
lib/ruwi/cli/command/pack.rb,
lib/ruwi/cli/command/setup.rb,
lib/ruwi/cli/command/rebuild.rb

Defined Under Namespace

Classes: Base, Dev, Pack, Rebuild, Setup

Constant Summary collapse

COMMANDS =
{
  "setup" => Command::Setup,
  "dev" => Command::Dev,
  "pack" => Command::Pack,
  "rebuild" => Command::Rebuild
}.freeze

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruwi/cli/command.rb', line 18

def self.run(argv)
  command_name = argv[0]

  if command_name.nil?
    show_usage
    raise SystemExit.new(1)
  end

  command_class = COMMANDS[command_name]
  if command_class.nil?
    puts "Unknown command: #{command_name}"
    puts ""
    show_usage
    raise SystemExit.new(1)
  end

  command_class.new.run(argv[1..-1])
end

.show_usageObject



37
38
39
40
41
42
43
44
45
# File 'lib/ruwi/cli/command.rb', line 37

def self.show_usage
  puts "Usage: ruwi <command>"
  puts ""
  puts "Commands:"
  COMMANDS.each do |name, klass|
    description = klass.description || ""
    puts "  #{name.ljust(12)}#{description}"
  end
end