summaryrefslogtreecommitdiffstats
path: root/bin/ColonialTwilight.rb
blob: 9a376c979d1dd73d51ce26cde782694596086834 (plain)
1
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-

require 'optparse'

require 'colonial_twilight'

class OptParser

  class Options

    attr_accessor :verbose, :clearscreen

    def initialize
      @verbose = false
      @gui = false
      @clearscreen = false
    end

    def define_options(parser)
      parser.banner = "Usage: ColonialTwilight.rb [options]"
      parser.separator ""
      parser.separator "Specific options:"

      add_verbose(parser)
      add_gui(parser)
      add_clearscreen(parser)

      parser.separator ""
      parser.separator "Common options:"
      parser.on_tail("-h", "--help", "Show this message") do
        puts parser
        exit
      end
      parser.on_tail("--version", "Show version") do
        puts ColonialTwilight::VERSION
        exit
      end
    end

    def add_verbose(parser)
      parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
        @verbose = v
      end
    end
    def add_gui(parser)
      parser.on("-g", "--gui", "Run verbosely") do
        @gui = true
        puts "gui is not implemented yet ..."
        exit
      end
    end
    def add_clearscreen(parser)
      parser.on("-c", "--clearscreen", "Clear screen before each player turn") do |v|
        @clearscreen = true
      end
    end
  end

  def parse(args)
    @options = Options.new
    @parser = OptionParser.new do |parser|
      @options.define_options(parser)
      parser.parse!(args)
    end
    @options
  end
  attr_reader :parser, :options

end

parser = OptParser.new
options = parser.parse(ARGV)

require 'colonial_twilight/cli'
game = ColonialTwilight::Cli.new options
game.start