Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/core/opt_bool.rb
19721 views
1
# -*- coding: binary -*-
2
3
module Msf
4
# Boolean option type
5
class OptBool < OptBase
6
TRUE_REGEX = /^(y|yes|t|1|true)$/i
7
ANY_REGEX = /^(y|yes|n|no|t|f|0|1|true|false)$/i
8
9
# This overrides default from 'nil' to 'false'
10
def initialize(in_name, attrs = [],
11
default: false, **kwargs)
12
super
13
end
14
15
def type
16
return 'bool'
17
end
18
19
def valid?(value, check_empty: true, datastore: nil)
20
return false if check_empty && empty_required_value?(value)
21
return true if value.nil? && !required?
22
23
!(value.nil? ||
24
value.to_s.empty? ||
25
value.to_s.match(ANY_REGEX).nil?)
26
end
27
28
def normalize(value)
29
!(value.nil? ||
30
value.to_s.match(TRUE_REGEX).nil?)
31
end
32
end
33
end
34
35