Class: Msf::Ui::Formatter::OptionValidateError

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/ui/formatter/option_validate_error.rb

Class Method Summary collapse

Class Method Details

Print the ‘Msf::OptionValidateError` error in a human readable format

Parameters:

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/msf/ui/formatter/option_validate_error.rb', line 12

def self.print_error(mod, error)
  raise ArgumentError, "invalid error type #{error.class}, expected ::Msf::OptionValidateError" unless error.is_a?(::Msf::OptionValidateError)

  if error.reasons.empty?
    if error.message
      mod.print_error("#{error.class} #{error.message}")
    else
      mod.print_error("#{error.class} The following options failed to validate: #{error.options.join(', ')}")
    end
  else
    mod.print_error("#{error.class} The following options failed to validate:")
    error.options.sort.each do |option_name|
      reasons = error.reasons[option_name]
      if reasons
        mod.print_error("Invalid option #{option_name}: #{reasons.join(', ')}")
      else
        mod.print_error("Invalid option #{option_name}")
      end
    end
  end
end