metasploit-framework/lib/msf/core/opt_enum.rb

50 lines
940 B
Ruby
Raw Normal View History

# -*- coding: binary -*-
module Msf
2017-09-21 02:17:51 +00:00
###
#
# Enum option.
#
###
class OptEnum < OptBase
def type
return 'enum'
end
2017-09-21 02:17:51 +00:00
# This overrides required default from 'false' to 'true'
def initialize(in_name, attrs = [],
required: true, desc: nil, default: nil, enums: [], aliases: [])
super
end
2017-09-21 02:17:51 +00:00
def valid?(value = self.value, check_empty: true)
return false if check_empty && empty_required_value?(value)
return true if value.nil? && !required?
!value.nil? && enums.include?(value.to_s)
end
2017-09-21 02:17:51 +00:00
def normalize(value = self.value)
if valid?(value)
value.to_s
else
nil
end
2017-09-21 02:17:51 +00:00
end
2017-09-21 02:17:51 +00:00
def desc=(value)
self.desc_string = value
desc
end
2017-09-21 02:17:51 +00:00
def desc
str = enums.join(', ') if enums
"#{desc_string || ''} (Accepted: #{str})"
end
2017-09-21 02:17:51 +00:00
protected
2017-09-21 02:17:51 +00:00
attr_accessor :desc_string # :nodoc:
end
end