2014-11-03 22:20:21 +00:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
|
|
|
module Msf
|
2017-09-21 02:17:51 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# Enum option.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class OptEnum < OptBase
|
|
|
|
def type
|
|
|
|
return 'enum'
|
|
|
|
end
|
2014-11-03 22:20:21 +00:00
|
|
|
|
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
|
2014-11-03 22:20:21 +00:00
|
|
|
|
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?
|
2014-11-03 22:20:21 +00:00
|
|
|
|
2017-09-21 13:05:33 +00:00
|
|
|
!value.nil? && enums.include?(value.to_s)
|
2014-11-03 22:20:21 +00:00
|
|
|
end
|
|
|
|
|
2017-09-21 02:17:51 +00:00
|
|
|
def normalize(value = self.value)
|
2017-09-21 07:33:37 +00:00
|
|
|
if valid?(value)
|
|
|
|
value.to_s
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2017-09-21 02:17:51 +00:00
|
|
|
end
|
2014-11-03 22:20:21 +00:00
|
|
|
|
2017-09-21 02:17:51 +00:00
|
|
|
def desc=(value)
|
|
|
|
self.desc_string = value
|
|
|
|
desc
|
|
|
|
end
|
2014-11-03 22:20:21 +00:00
|
|
|
|
2017-09-21 02:17:51 +00:00
|
|
|
def desc
|
|
|
|
str = enums.join(', ') if enums
|
|
|
|
"#{desc_string || ''} (Accepted: #{str})"
|
|
|
|
end
|
2014-11-03 22:20:21 +00:00
|
|
|
|
2017-09-21 02:17:51 +00:00
|
|
|
protected
|
2014-11-03 22:20:21 +00:00
|
|
|
|
2017-09-21 02:17:51 +00:00
|
|
|
attr_accessor :desc_string # :nodoc:
|
|
|
|
end
|
2014-11-03 22:20:21 +00:00
|
|
|
end
|