Class: Inform::Options::ArgumentsParser
- Defined in:
- lib/runtime/options.rb
Overview
The ArgumentsParser
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
- #admin ⇒ Object
- #banner ⇒ Object
- #flags ⇒ Object
- #help ⇒ Object
-
#initialize(args, option_parser = OptionParser.new, **params) ⇒ ArgumentsParser
constructor
A new instance of ArgumentsParser.
- #log_level ⇒ Object
- #version ⇒ Object
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 = ::Inform::Runtime.default_config.dup flags.each { |method_name| self.method(method_name).call } @parser.parse!(args, **params) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'lib/runtime/options.rb', line 32 def end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
32 33 34 |
# File 'lib/runtime/options.rb', line 32 def parser @parser end |
Instance Method Details
#admin ⇒ Object
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 [:admin] = true end end |
#banner ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/runtime/options.rb', line 45 def @parser. = "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 |
#flags ⇒ Object
41 42 43 |
# File 'lib/runtime/options.rb', line 41 def flags @flags ||= i[ admin log_level help version] end |
#help ⇒ Object
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_level ⇒ Object
60 61 62 63 64 65 |
# File 'lib/runtime/options.rb', line 60 def log_level @parser.on_tail('-v', '--verbose', 'Increase verbosity') do [:log_level] ||= Logger::INFO [:log_level] -= 1 end end |
#version ⇒ Object
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 |