opt_parse_validator 1.7.4 → 1.9.1

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
  SHA256:
3
- metadata.gz: bfcde1ed88a3d3b41836d151c76a25e1f5c6f36e5e62a2910878d9463dc8bddd
4
- data.tar.gz: 6d07487070338fb64622883ed0c7d5cc70cc90e50d0c32ef56e48ebab47bdb07
3
+ metadata.gz: 3ccb947d9079bcc004e16bdfea47a5e5207c26e871da1a1cf0c01f2bbeca5b65
4
+ data.tar.gz: 87139c6bbe1664ff3c70374a81d3e6940193b5d46cd0d07c5905cc22ab468cfb
5
5
  SHA512:
6
- metadata.gz: efc33f8e0cc1522c8d7b22d1bff81227f26bf67693c3ea14800d34e361bcf0a76d7b04aa656bfc5ce19c10b6a78a37d03b146ff75ac141b1db629ce90e95699d
7
- data.tar.gz: 5dba47501b4d609120a4033e1531ffe7af505e4bbd72aaea5a5725b1d00d61eddde009aa94096656a1fab9346c98e433a74be58dda68d67ea1cbe2ebd1032cf4
6
+ metadata.gz: dd7dd0aa734ad3ad63bd1644b8ab05213d96a0d3c223de20d2152581c22c04b7f68df65ea52fbe4b189e46d44b32d005b855da92e12c5e336b31eb42553d5c00
7
+ data.tar.gz: 50bca2d9e0f17c6c1f9662b3d3e6a9d9b1d8ed5352b6e35c4847ac373ff91b64a50adfe53ffd73f993575e90a9cae67cfe7bcd52fafe702cefb30ec44d718dce
data/README.md CHANGED
@@ -2,7 +2,7 @@ OptParseValidator
2
2
  =================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/opt_parse_validator.svg)](https://badge.fury.io/rb/opt_parse_validator)
5
- [![Build Status](https://travis-ci.org/wpscanteam/OptParseValidator.svg?branch=master)](https://travis-ci.org/wpscanteam/OptParseValidator)
5
+ ![Build](https://github.com/wpscanteam/OptParseValidator/workflows/Build/badge.svg)
6
6
  [![Coverage Status](https://img.shields.io/coveralls/wpscanteam/OptParseValidator.svg)](https://coveralls.io/r/wpscanteam/OptParseValidator?branch=master)
7
7
  [![Code Climate](https://api.codeclimate.com/v1/badges/56f0307bbbda6d41b99a/maintainability)](https://codeclimate.com/github/wpscanteam/OptParseValidator/maintainability)
8
8
 
@@ -29,8 +29,8 @@ module OptParseValidator
29
29
  end
30
30
 
31
31
  # @return [ OptParseValidator::ConfigFilesLoaderMerger ]
32
- def options_files
33
- @options_files ||= ConfigFilesLoaderMerger.new
32
+ def config_files
33
+ @config_files ||= ConfigFilesLoaderMerger.new
34
34
  end
35
35
 
36
36
  # @param [ Array<OptBase> ] options
@@ -56,7 +56,7 @@ module OptParseValidator
56
56
 
57
57
  # @return [ Hash ]
58
58
  def results(argv = default_argv)
59
- load_options_files
59
+ load_config_files
60
60
  parse!(argv)
61
61
  post_processing
62
62
 
@@ -108,24 +108,22 @@ module OptParseValidator
108
108
  # @return [ void ]
109
109
  def register_callback(opt)
110
110
  on(*opt.option) do |arg|
111
- begin
112
- if opt.alias?
113
- parse!(opt.alias_for.split(' '))
114
- else
115
- @results[opt.to_sym] = opt.normalize(opt.validate(arg))
116
- end
117
- rescue StandardError => e
118
- # Adds the long option name to the message
119
- # And raises it as an OptParseValidator::Error if not already one
120
- # e.g --proxy Invalid Scheme format.
121
- raise e.is_a?(Error) ? e.class : Error, "#{opt.to_long} #{e}"
111
+ if opt.alias?
112
+ parse!(opt.alias_for.split(' '))
113
+ else
114
+ @results[opt.to_sym] = opt.normalize(opt.validate(arg))
122
115
  end
116
+ rescue StandardError => e
117
+ # Adds the long option name to the message
118
+ # And raises it as an OptParseValidator::Error if not already one
119
+ # e.g --proxy Invalid Scheme format.
120
+ raise e.is_a?(Error) ? e.class : Error, "#{opt.to_long} #{e}"
123
121
  end
124
122
  end
125
123
 
126
124
  # @return [ Void ]
127
- def load_options_files
128
- files_data = options_files.parse(symbolize_keys: true)
125
+ def load_config_files
126
+ files_data = config_files.parse
129
127
 
130
128
  @opts.each do |opt|
131
129
  next unless files_data.key?(opt.to_sym)
@@ -147,11 +145,11 @@ module OptParseValidator
147
145
  # @return [ Void ]
148
146
  def post_processing
149
147
  @opts.each do |opt|
150
- raise NoRequiredOption, "The option #{opt} is required" if opt.required? && !@results.key?(opt.to_sym)
148
+ raise NoRequiredOption, "The option --#{opt} is required" if opt.required? && !@results.key?(opt.to_sym)
151
149
 
152
150
  next if opt.required_unless.empty? || @results.key?(opt.to_sym)
153
151
 
154
- fail_msg = "One of the following options is required: #{opt}, #{opt.required_unless.join(', ')}"
152
+ fail_msg = "One of the following options is required: --#{opt}, --#{opt.required_unless.join(', --')}"
155
153
 
156
154
  raise NoRequiredOption, fail_msg unless opt.required_unless.any? do |sym|
157
155
  @results.key?(sym)
@@ -6,12 +6,11 @@ require_relative 'config_files_loader_merger/yml'
6
6
 
7
7
  # :nocov:
8
8
  # @param [ String ] path The path of the file to load
9
- # @param [ Hash ] opts See https://ruby-doc.org/stdlib-2.6.3/libdoc/psych/rdoc/Psych.html#method-c-safe_load
10
- def yaml_safe_load(path, opts = {})
9
+ def yaml_safe_load(path)
11
10
  if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') # Ruby 2.6
12
- YAML.safe_load(File.read(path), opts) || {}
11
+ YAML.safe_load(File.read(path), permitted_classes: [Regexp]) || {}
13
12
  else
14
- YAML.safe_load(File.read(path), opts[:permitted_classes] || [], opts[:permitted_symbols] || [], opts[:aliases]) || {}
13
+ YAML.safe_load(File.read(path), [Regexp]) || {}
15
14
  end
16
15
  end
17
16
  # :nocov:
@@ -29,6 +28,8 @@ module OptParseValidator
29
28
  extensions.map { |sym| sym.to_s.downcase }
30
29
  end
31
30
 
31
+ attr_accessor :result_key
32
+
32
33
  # @param [ String ] file_path
33
34
  #
34
35
  # @return [ Self ]
@@ -43,16 +44,16 @@ module OptParseValidator
43
44
  end
44
45
 
45
46
  # @params [ Hash ] opts
46
- # @option opts [ Boolean ] :symbolize_keys Whether or not to symbolize keys in the returned hash
47
- # @option opts [ Array ] :yaml_arguments See https://ruby-doc.org/stdlib-2.3.1/libdoc/psych/rdoc/Psych.html#method-c-safe_load
48
47
  #
49
48
  # @return [ Hash ]
50
- def parse(opts = {})
49
+ def parse
51
50
  result = {}
52
51
 
53
- each { |option_file| result.deep_merge!(option_file.parse(opts)) }
52
+ each { |config_file| result.deep_merge!(config_file.parse) }
53
+
54
+ result = result.dig(result_key) || {} if result_key
54
55
 
55
- opts[:symbolize_keys] ? result.deep_symbolize_keys : result
56
+ result.deep_symbolize_keys
56
57
  end
57
58
  end
58
59
  end
@@ -12,9 +12,8 @@ module OptParseValidator
12
12
  @path = path
13
13
  end
14
14
 
15
- # @params [ Hash ] opts
16
15
  # @return [ Hash ] a { 'key' => value } hash
17
- def parse(_opts = {})
16
+ def parse
18
17
  raise NotImplementedError
19
18
  end
20
19
 
@@ -7,9 +7,8 @@ module OptParseValidator
7
7
  module ConfigFile
8
8
  # Json Implementation
9
9
  class JSON < Base
10
- # @params [ Hash ] opts
11
10
  # @return [ Hash ] a { 'key' => value } hash
12
- def parse(_opts = {})
11
+ def parse
13
12
  ::JSON.parse(File.read(path))
14
13
  end
15
14
  end
@@ -7,12 +7,9 @@ module OptParseValidator
7
7
  module ConfigFile
8
8
  # Yaml Implementation
9
9
  class YML < Base
10
- # @params [ Hash ] opts
11
- # @option opts [ Hash ] :yaml_options See https://ruby-doc.org/stdlib-2.6.3/libdoc/psych/rdoc/Psych.html#method-c-safe_load
12
- #
13
10
  # @return [ Hash ] a { 'key' => value } hash
14
- def parse(opts = {})
15
- yaml_safe_load(path, opts[:yaml_options] || {})
11
+ def parse
12
+ yaml_safe_load(path)
16
13
  end
17
14
  end
18
15
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OptionParser
4
- # Hack to suppress the completion (expect for the -h/--help) which was leading to
4
+ # Hack to suppress the completion (except for the -h/--help) which was leading to
5
5
  # unwanted behaviours
6
6
  # See https://github.com/wpscanteam/CMSScanner/issues/2
7
7
  module Completion
@@ -107,7 +107,7 @@ module OptParseValidator
107
107
 
108
108
  raise Error, "Could not find option symbol for #{option}" unless long_option
109
109
 
110
- @symbol = long_option.gsub(/^--/, '').tr('-', '_').to_sym
110
+ @symbol = long_option.delete_prefix('--').tr('-', '_').to_sym
111
111
  end
112
112
  @symbol
113
113
  end
@@ -115,7 +115,7 @@ module OptParseValidator
115
115
  # @return [ String ] The raw long option (e.g: --proxy)
116
116
  def to_long
117
117
  option.each do |option_attr|
118
- if /^--/.match?(option_attr)
118
+ if option_attr.start_with?('--')
119
119
  return option_attr.gsub(/ .*$/, '')
120
120
  .gsub(/\[[^\]]+\]/, '')
121
121
  end
@@ -94,7 +94,7 @@ module OptParseValidator
94
94
  # @return [ Array ]
95
95
  def value_from_pattern(item)
96
96
  choices.each do |key, opt|
97
- next unless item =~ /\A#{key.to_s}(.*)\z/
97
+ next unless item =~ /\A#{key}(.*)\z/
98
98
 
99
99
  return [opt, Regexp.last_match[1]]
100
100
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Gem Version
4
4
  module OptParseValidator
5
- VERSION = '1.7.4'
5
+ VERSION = '1.9.1'
6
6
  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: 1.7.4
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - WPScanTeam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-31 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 5.3.0
22
+ version: 6.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.2'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 5.3.0
32
+ version: 6.1.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: addressable
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '2.5'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '2.7'
42
+ version: '2.8'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '2.5'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '2.7'
52
+ version: '2.8'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: bundler
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -65,103 +65,103 @@ dependencies:
65
65
  - !ruby/object:Gem::Version
66
66
  version: '1.6'
67
67
  - !ruby/object:Gem::Dependency
68
- name: coveralls
68
+ name: rake
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: 0.8.0
73
+ version: '13.0'
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: 0.8.0
80
+ version: '13.0'
81
81
  - !ruby/object:Gem::Dependency
82
- name: rake
82
+ name: rspec
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '12.3'
87
+ version: 3.9.0
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
- version: '12.3'
94
+ version: 3.9.0
95
95
  - !ruby/object:Gem::Dependency
96
- name: rspec
96
+ name: rspec-its
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: 3.8.0
101
+ version: 1.3.0
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: 3.8.0
108
+ version: 1.3.0
109
109
  - !ruby/object:Gem::Dependency
110
- name: rspec-its
110
+ name: rubocop
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: 1.3.0
115
+ version: 0.84.0
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: 1.3.0
122
+ version: 0.84.0
123
123
  - !ruby/object:Gem::Dependency
124
- name: rubocop
124
+ name: rubocop-performance
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: 0.73.0
129
+ version: 1.6.0
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: 0.73.0
136
+ version: 1.6.0
137
137
  - !ruby/object:Gem::Dependency
138
- name: rubocop-performance
138
+ name: simplecov
139
139
  requirement: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: 1.4.0
143
+ version: 0.18.2
144
144
  type: :development
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: 1.4.0
150
+ version: 0.18.2
151
151
  - !ruby/object:Gem::Dependency
152
- name: simplecov
152
+ name: simplecov-lcov
153
153
  requirement: !ruby/object:Gem::Requirement
154
154
  requirements:
155
155
  - - "~>"
156
156
  - !ruby/object:Gem::Version
157
- version: 0.16.1
157
+ version: 0.8.0
158
158
  type: :development
159
159
  prerelease: false
160
160
  version_requirements: !ruby/object:Gem::Requirement
161
161
  requirements:
162
162
  - - "~>"
163
163
  - !ruby/object:Gem::Version
164
- version: 0.16.1
164
+ version: 0.8.0
165
165
  description: Implementation of validators for the ruby OptionParser lib. Mainly used
166
166
  in the CMSScanner gem to define the cli options available
167
167
  email:
@@ -213,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
213
  requirements:
214
214
  - - ">="
215
215
  - !ruby/object:Gem::Version
216
- version: '2.4'
216
+ version: '2.5'
217
217
  required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  requirements:
219
219
  - - ">="