opt_parse_validator 0.0.13.8 → 0.0.13.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8b96bf2df00c21b5dd5be7b553495196f7f7190
4
- data.tar.gz: 7091246c62fe01bb6a1437ba265ef5d755409d46
3
+ metadata.gz: d415463f07cdf6040286e6d663e30e595dd1baa5
4
+ data.tar.gz: afd3bdd186e2509e4b7374c6922eba90c37cc350
5
5
  SHA512:
6
- metadata.gz: '0338d5ddadd4aeef34af392f5aa3d51ada1deb93cffe3f04cb7fb86073c6c8613e8b9b70f78b833a2106e2ff9ac35605b9b65b792cb3f66eb2ecf859c7fcea5f'
7
- data.tar.gz: b0641b222b4f7ff8136e5bfaa4d6fb2d2e61543ed1fd915e526470b4ae03282b38ac9ee143bce8f077f0f9180053bbd17fbc021028cc3b7e22f8a6c09a05d317
6
+ metadata.gz: a8a1f3f9423004010b3063deac7ad196f054b1a8b5f3ca2d4a06465312a292051b384c007aa65a1556ba594cd49621fe52dc855d255195ca04cd3bc5fd1e23ec
7
+ data.tar.gz: 47629f4e35fa33ad43c2ac16682a6ef32b040828f62886259f4289ecefda410a75f46b8e0ad32fed09d1bd97335183e24a3bfe10333afe12736823a5c964fb73
data/README.md CHANGED
@@ -47,6 +47,14 @@ For more option examples, see
47
47
 
48
48
  Please Feel free to send Pull Requests to improve this Readme
49
49
 
50
+ ### Global Attributes
51
+
52
+ Some attributes are available for all Validators:
53
+ - :required (whether or not the associated cli option is required/mandatory - [example](https://github.com/wpscanteam/CMSScanner/blob/master/app/controllers/core/cli_options.rb#L9)).
54
+ - :required_unless (like the above, except if the option/s given in this parameter are called in the CLI - [example](https://github.com/wpscanteam/wpscan-v3/blob/master/app/controllers/core.rb#L7), can be a single symbol or array of symbols)
55
+ - :default (Default value to use if the option is not supplied)
56
+ - :value_if_empty (Value to use if no argument has been supplied for the related option)
57
+
50
58
  ### Available Validators & Associated Attributes:
51
59
  - Array
52
60
  - :separator (default: ',')
@@ -72,7 +80,6 @@ Please Feel free to send Pull Requests to improve this Readme
72
80
  - MultiChoices
73
81
  - choices (mandatory)
74
82
  - separator (default: ',')
75
- - value_if_empty
76
83
  - incompatible
77
84
  - Positive Integer
78
85
  - Path
@@ -87,6 +94,8 @@ Please Feel free to send Pull Requests to improve this Readme
87
94
  - :default_protocol
88
95
  - Regexp:
89
96
  - :options (See http://ruby-doc.org/core-2.2.1/Regexp.html#method-c-new)
97
+ - SmartList
98
+ - separator (default: ',')
90
99
  - String
91
100
  - URI
92
101
  - :protocols
@@ -1,6 +1,7 @@
1
1
  %w[
2
2
  base string integer positive_integer choice boolean uri url proxy credentials
3
3
  path file_path directory_path array integer_range multi_choices regexp headers
4
+ smart_list
4
5
  ].each do |opt|
5
6
  require 'opt_parse_validator/opts/' + opt
6
7
  end
@@ -4,6 +4,8 @@ module OptParseValidator
4
4
  # @return [ Void ]
5
5
  def append_help_messages
6
6
  option << "Separator to use between the values: '#{separator}'"
7
+
8
+ super
7
9
  end
8
10
 
9
11
  # @param [ String ] value
@@ -10,7 +10,7 @@ module OptParseValidator
10
10
  # @option attrs [ Boolean ] :required
11
11
  # @options attrs [ Array<Symbol>, Symbol ] :required_unless
12
12
  # @option attrs [ Mixed ] :default The default value to use if the option is not supplied
13
- # @option attrs [ Mixed ] :value_if_empty The value to use if no arguments have been supplied
13
+ # @option attrs [ Mixed ] :value_if_empty The value to use if no argument has been supplied
14
14
  # @option attrs [ Array<Symbol> ] :normalize See #normalize
15
15
  #
16
16
  # @note The :default and :normalize 'logics' are done in OptParseValidator::OptParser#add_option
@@ -18,12 +18,17 @@ module OptParseValidator
18
18
  @option = option
19
19
  @attrs = attrs
20
20
 
21
- append_help_messages if respond_to?(:append_help_messages)
21
+ # TODO: incompatible attributes, ie required and require_unless at the same time
22
+
23
+ append_help_messages
22
24
  end
23
25
 
24
26
  # @return [ Void ]
25
27
  def append_help_messages
26
28
  option << "Default: #{default}" if default
29
+ option << "Value if no argument supplied: #{value_if_empty}" if value_if_empty
30
+ option << 'This option is mandatory' if required?
31
+ option << "This option is mandatory unless #{required_unless.join(' or ')} is/are supplied" unless required_unless.empty?
27
32
  end
28
33
 
29
34
  # @return [ Boolean ]
@@ -14,13 +14,9 @@ module OptParseValidator
14
14
 
15
15
  # @return [ Void ]
16
16
  def append_help_messages
17
- msg = 'Available choices:'
17
+ super
18
18
 
19
- choices.each do |choice|
20
- msg += choice.to_s == default.to_s ? " #{choice} (default)," : " #{choice},"
21
- end
22
-
23
- option << msg[0..-2]
19
+ option << "Available choices: #{choices.join(', ')}"
24
20
  end
25
21
 
26
22
  # @return [ String ]
@@ -3,6 +3,8 @@ module OptParseValidator
3
3
  class OptHeaders < OptBase
4
4
  # @return [ Void ]
5
5
  def append_help_messages
6
+ super
7
+
6
8
  option << "Separator to use between the headers: '; '"
7
9
  option << "Examples: 'X-Forwarded-For: 127.0.0.1', 'X-Forwarded-For: 127.0.0.1; Another: aaa'"
8
10
  end
@@ -4,7 +4,8 @@ module OptParseValidator
4
4
  # @return [ Void ]
5
5
  def append_help_messages
6
6
  option << "Range separator to use: '#{separator}'"
7
- option << "If no range is supplied, #{value_if_empty} will be used" if value_if_empty
7
+
8
+ super
8
9
  end
9
10
 
10
11
  # @param [ String ] value
@@ -18,8 +18,7 @@ module OptParseValidator
18
18
 
19
19
  append_choices_help_messages
20
20
 
21
- option << "Multiple choices can be supplied, use the '#{separator}' char as a separator"
22
- option << "If no choice is supplied, '#{value_if_empty}' will be used" if value_if_empty
21
+ super
23
22
 
24
23
  append_incompatible_help_messages
25
24
  end
@@ -0,0 +1,28 @@
1
+ module OptParseValidator
2
+ # Implementation of the SmartList Option
3
+ # Such option allow users to supply a list like
4
+ # - name1
5
+ # - name1,name2,name3
6
+ # - /tmp/names.txt
7
+ class OptSmartList < OptArray
8
+ # @return [ Void ]
9
+ def append_help_messages
10
+ super
11
+ # removes the help message from OptArray about the separator as useless here
12
+ # can't use option as it's an attr_reader only
13
+ @option -= ["Separator to use between the values: '#{separator}'"]
14
+
15
+ option << "Examples: 'a1', '#{%w[a1 a2 a3].join(separator)}', '/tmp/a.txt'"
16
+ end
17
+
18
+ # @param [ String ] value
19
+ #
20
+ # @return [ Array<String> ]
21
+ def validate(value)
22
+ # Might be a better way to do this especially with a big file
23
+ File.open(value).map(&:chomp)
24
+ rescue Errno::ENOENT
25
+ super(value)
26
+ end
27
+ end
28
+ end
@@ -5,6 +5,8 @@ module OptParseValidator
5
5
  def append_help_messages
6
6
  option << "Allowed Protocols: #{allowed_protocols.join(', ')}" unless allowed_protocols.empty?
7
7
  option << "Default Protocol if none provided: #{default_protocol}" if default_protocol
8
+
9
+ super
8
10
  end
9
11
 
10
12
  # @return [ Array<String> ]
@@ -1,4 +1,4 @@
1
1
  # Gem Version
2
2
  module OptParseValidator
3
- VERSION = '0.0.13.8'.freeze
3
+ VERSION = '0.0.13.9'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opt_parse_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13.8
4
+ version: 0.0.13.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - WPScanTeam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-04 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -170,6 +170,7 @@ files:
170
170
  - lib/opt_parse_validator/opts/positive_integer.rb
171
171
  - lib/opt_parse_validator/opts/proxy.rb
172
172
  - lib/opt_parse_validator/opts/regexp.rb
173
+ - lib/opt_parse_validator/opts/smart_list.rb
173
174
  - lib/opt_parse_validator/opts/string.rb
174
175
  - lib/opt_parse_validator/opts/uri.rb
175
176
  - lib/opt_parse_validator/opts/url.rb