Class: OptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_arena/option_parser.rb

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_arena/option_parser.rb', line 2

def self.parse(args)
  options = {}

  opt_parser = OptionParser.new do |opts|
    opts.banner = %{Usage: ruby_arena -l <level> [ai_file]
Usage: ruby_arena <ai_file1> [ai_file2] ... [ai_fileN]
    }

    opts.on("-l", "--level level_number", Integer, "Specify level") do |l|
      options[:level] = l
    end

    if args.empty?
      puts opts
      exit
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end

  opt_parser.parse!(args)

  options
end