File tree Expand file tree Collapse file tree 1 file changed +21
-38
lines changed Expand file tree Collapse file tree 1 file changed +21
-38
lines changed Original file line number Diff line number Diff line change 1
1
# -*- coding: binary -*-
2
2
3
3
module Msf
4
-
5
- ###
6
- #
7
- # Boolean option.
8
- #
9
- ###
10
- class OptBool < OptBase
11
-
12
- TrueRegex = /^(y|yes|t|1|true)$/i
13
-
14
- def type
15
- return 'bool'
16
- end
17
-
18
- def valid? ( value , check_empty : true )
19
- return false if empty_required_value? ( value )
20
-
21
- if ( ( value != nil and
22
- ( value . to_s . empty? == false ) and
23
- ( value . to_s . match ( /^(y|yes|n|no|t|f|0|1|true|false)$/i ) == nil ) ) )
24
- return false
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
+ required : true , desc : nil , default : false , aliases : [ ] )
12
+ super
25
13
end
26
14
27
- true
28
- end
29
-
30
- def normalize ( value )
31
- if ( value . nil? or value . to_s . match ( TrueRegex ) . nil? )
32
- false
33
- else
34
- true
15
+ def type
16
+ return 'bool'
35
17
end
36
- end
37
18
38
- def is_true? ( value )
39
- return normalize ( value )
40
- end
19
+ def valid? ( value , check_empty : true )
20
+ return false if check_empty && empty_required_value? ( value )
21
+ !( value . nil? ||
22
+ value . to_s . empty? ||
23
+ value . to_s . match ( ANY_REGEX ) . nil? )
24
+ end
41
25
42
- def is_false? ( value )
43
- return !is_true? ( value )
26
+ def normalize ( value )
27
+ !( value . nil? ||
28
+ value . to_s . match ( TRUE_REGEX ) . nil? )
29
+ end
44
30
end
45
-
46
- end
47
-
48
31
end
You can’t perform that action at this time.
0 commit comments