Module: Inform::Options

Included in:
App
Defined in:
lib/runtime/options.rb

Overview

The Options module

Defined Under Namespace

Classes: ArgumentsParser

Instance Method Summary collapse

Instance Method Details

#demand(options, arg, positional = false) ⇒ Object

class ArgumentsParser

Raises:

  • (UserError)


83
84
85
86
87
# File 'lib/runtime/options.rb', line 83

def demand(options, arg, positional = false)
  return options[arg] unless options[arg].nil?
  required_arg = positional ? "<#{arg}>" : "--#{arg.to_s.gsub(/_/, '-')}"
  raise UserError, "Required argument: #{required_arg}"
end

#parse_arguments(args = ARGV, _file_path = ARGF) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/runtime/options.rb', line 89

def parse_arguments(args = ARGV, _file_path = ARGF)
  arguments_parser = ArgumentsParser.new(args)
  demand(arguments_parser.options, :game_path)
  arguments_parser.options
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption,
       OptionParser::MissingArgument, OptionParser::NeedlessArgument => e
  puts e.message
  puts arguments_parser.parser
  exit
rescue OptionParser::AmbiguousOption => e
  abort e.message
end