Class: Inform::Options::ArgumentsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/runtime/options.rb

Overview

The ArgumentsParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, option_parser = OptionParser.new, **params) ⇒ ArgumentsParser

Returns a new instance of ArgumentsParser.



34
35
36
37
38
39
# File 'lib/runtime/options.rb', line 34

def initialize(args, option_parser = OptionParser.new, **params)
  @parser = option_parser
  @options = ::Inform::Runtime.default_config.dup
  flags.each { |method_name| self.method(method_name).call }
  @parser.parse!(args, **params)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



32
33
34
# File 'lib/runtime/options.rb', line 32

def options
  @options
end

#parserObject (readonly)

Returns the value of attribute parser.



32
33
34
# File 'lib/runtime/options.rb', line 32

def parser
  @parser
end

Instance Method Details

#adminObject



54
55
56
57
58
# File 'lib/runtime/options.rb', line 54

def admin
  @parser.on_tail('--admin', 'Set player character as admin; default: false') do
    @options[:admin] = true
  end
end


45
46
47
48
49
50
51
52
# File 'lib/runtime/options.rb', line 45

def banner
  @parser.banner = "Usage: #{File.basename($PROGRAM_NAME)} [game_path] [options]"
  @parser.separator ''
  @parser.separator 'Arguments:'
  @parser.separator '    game_path                        Path to game file or directory'
  @parser.separator ''
  @parser.separator 'Options:'
end

#flagsObject



41
42
43
# File 'lib/runtime/options.rb', line 41

def flags
  @flags ||= i[banner admin log_level help version]
end

#helpObject



67
68
69
70
71
72
# File 'lib/runtime/options.rb', line 67

def help
  @parser.on_tail('-?', '--help', 'Show this message') do
    puts @parser
    exit
  end
end

#log_levelObject



60
61
62
63
64
65
# File 'lib/runtime/options.rb', line 60

def log_level
  @parser.on_tail('-v', '--verbose', 'Increase verbosity') do
    @options[:log_level] ||= Logger::INFO
    @options[:log_level] -= 1
  end
end

#versionObject



74
75
76
77
78
79
# File 'lib/runtime/options.rb', line 74

def version
  @parser.on_tail('--version', 'Show version') do
    puts "#{$PROGRAM_NAME} version #{Inform::VERSION}"
    exit
  end
end