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
-
#demand(options, arg, positional = false) ⇒ Object
class ArgumentsParser.
- #parse_arguments(args: ARGV, defaults: {}, _file_path: ARGF) ⇒ Object
Instance Method Details
#demand(options, arg, positional = false) ⇒ Object
class ArgumentsParser
130 131 132 133 134 |
# File 'lib/story_teller/options.rb', line 130 def demand(, arg, positional = false) return [arg] unless [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., :game_path) arguments_parser. rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::NeedlessArgument => e puts e. puts arguments_parser.parser exit rescue OptionParser::AmbiguousOption => e abort e. end |