Class: Hyrum::ScriptOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrum/script_options.rb

Constant Summary collapse

MANDATORY_OPTIONS =
%i[message].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ScriptOptions

Returns a new instance of ScriptOptions.



13
14
15
16
17
18
19
20
21
22
# File 'lib/hyrum/script_options.rb', line 13

def initialize(args)
  @options = {
    message: nil,
    validate: false,
    min_quality: 70,
    strict: false,
    show_scores: false
  }
  @args = args
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/hyrum/script_options.rb', line 11

def options
  @options
end

Instance Method Details

#parseObject

rubocop:disable Metrics/MethodLength



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hyrum/script_options.rb', line 25

def parse
  OptionParser.new do |parser|
    define_options(parser)
    parser.parse!(@args)
  end
  enforce_mandatory_options
  set_dynamic_defaults
  options
rescue OptionParser::InvalidOption => e
  raise ScriptOptionsError, "Invalid option: #{e.message}"
rescue OptionParser::MissingArgument => e
  raise ScriptOptionsError, "Missing argument for option: #{e.message}"
rescue OptionParser::InvalidArgument => e
  raise ScriptOptionsError, "Invalid argument for option: #{e.message}"
end