Class: WhirledPeas::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/whirled_peas/command_line.rb

Constant Summary collapse

COMMANDS =
[
  Command::Debug,
  Command::Fonts,
  Command::Frames,
  Command::Help,
  Command::Play,
  Command::Record,
  Command::Still,
  Command::Themes
].map.with_object({}) { |c, h| h[c.command_name] = c }

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CommandLine

Returns a new instance of CommandLine.



23
24
25
# File 'lib/whirled_peas/command_line.rb', line 23

def initialize(args)
  @args = args
end

Instance Method Details

#startObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/whirled_peas/command_line.rb', line 27

def start
  if args.length < 1
    print_usage
    exit(1)
  end

  command = args.shift

  unless COMMANDS.key?(command)
    puts "Unrecognized command: #{command}"
    print_usage
    exit(1)
  end

  cmd = COMMANDS[command].new(args, WhirledPeas.config)

  unless cmd.valid?
    cmd.print_error
    exit(1)
  end

  cmd.start
end