Module: StoryTeller::Options

Included in:
Cli
Defined in:
lib/story_teller/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:



130
131
132
133
134
# File 'lib/story_teller/options.rb', line 130

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, defaults: {}, _file_path: ARGF) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/story_teller/options.rb', line 136

def parse_arguments(args: ARGV, defaults: {}, _file_path: ARGF)
  arguments_parser = ArgumentsParser.new(args, defaults)
  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