opt_parse_validator 0.0.16.3 → 0.0.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +19 -0
- data/README.md +110 -0
- data/lib/opt_parse_validator/opts/base.rb +5 -0
- data/lib/opt_parse_validator/version.rb +1 -1
- data/lib/opt_parse_validator.rb +25 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4db0514a69c11f2c171f1e5647fbdfe93d932993
|
|
4
|
+
data.tar.gz: 5a22eaa6aa48b06f1317178ad00e73540a576a76
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a660a58bb66d6a0013f366b337016bdffb23c36d520ec1db5cffe2bec6fd8807445ccb2e81fed594437692fec09a419c099f3e1a3ccd8368860bb3207e478d7e
|
|
7
|
+
data.tar.gz: a7994dfd31552f5d8c972593b44e167c741cd6d80f5ddec73447ba5c887619dd0964be66b4b05deac952470aa9b95c70f7dae86689cf1854a650043c7bb0c04c
|
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (C) 2014-2015 - WPScanTeam
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
OptParseValidator
|
|
2
|
+
=================
|
|
3
|
+
|
|
4
|
+
[](https://badge.fury.io/rb/opt_parse_validator)
|
|
5
|
+
[](https://travis-ci.org/wpscanteam/OptParseValidator)
|
|
6
|
+
[](https://coveralls.io/r/wpscanteam/OptParseValidator?branch=master)
|
|
7
|
+
[](https://codeclimate.com/github/wpscanteam/OptParseValidator/maintainability)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Installation
|
|
11
|
+
|
|
12
|
+
```gem install opt_parse_validator```
|
|
13
|
+
|
|
14
|
+
### Usage Example
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
# test.rb
|
|
18
|
+
|
|
19
|
+
require 'opt_parse_validator'
|
|
20
|
+
|
|
21
|
+
begin
|
|
22
|
+
# For constructor options, such as setting a banner, the summary width and indent,
|
|
23
|
+
# see http://ruby-doc.org/stdlib-2.4.2/libdoc/optparse/rdoc/OptionParser.html#method-c-new
|
|
24
|
+
parsed_cli_options = OptParseValidator::OptParser.new.add(
|
|
25
|
+
OptParseValidator::OptString.new(['-m', '--mandatory PARAM', 'A Mandatory CLI option'], required: true),
|
|
26
|
+
OptParseValidator::OptBoolean.new(['--test', '-t', 'Option Helper Message']),
|
|
27
|
+
OptParseValidator::OptFilePath.new(['-o', '--output FILE', 'Output to FILE'], writable: true, exists: false),
|
|
28
|
+
OptParseValidator::OptAlias.new(['--alias', '-a'], alias_for: '--test -o file.txt')
|
|
29
|
+
).results
|
|
30
|
+
|
|
31
|
+
p parsed_cli_options
|
|
32
|
+
rescue OptParseValidator::Error => e
|
|
33
|
+
puts 'Parsing Error: ' + e.message
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Then have a play with
|
|
38
|
+
```ruby test.rb -h```
|
|
39
|
+
```ruby test.rb -m hh -t```
|
|
40
|
+
```ruby test.rb -t```
|
|
41
|
+
|
|
42
|
+
It is worth to note that when aliases are used, it is recommended to provide them first in the CLI. Otherwise, they might override user-suplied cli options. For example, using the options above, ```ruby test.rb -m aa -o override.txt --alias``` won't have the desired effect (to have --output as override.txt), but ```ruby test.rb --alias -m aa -o override.txt``` will.
|
|
43
|
+
|
|
44
|
+
For more option examples, see
|
|
45
|
+
- https://github.com/wpscanteam/CMSScanner/blob/master/app/controllers/core/cli_options.rb
|
|
46
|
+
- https://github.com/wpscanteam/wpscan/blob/master/app/controllers/enumeration/cli_options.rb
|
|
47
|
+
|
|
48
|
+
Please feel free to send Pull Requests to improve this Readme
|
|
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/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, the correct format has to be used as it won't go through the validation and normalization processes)
|
|
56
|
+
- :value_if_empty (Value to use if no argument has been supplied for the related option)
|
|
57
|
+
- :advanced (Whether or or not the option is an advanced one. If set to true, the option won't be displayed in the #simple_help, but will in the #full_help)
|
|
58
|
+
|
|
59
|
+
### Available Validators & Associated Attributes:
|
|
60
|
+
- Alias:
|
|
61
|
+
- :alias_for (mandatory)
|
|
62
|
+
- Array
|
|
63
|
+
- :separator (default: ',')
|
|
64
|
+
- Boolean
|
|
65
|
+
- Choice
|
|
66
|
+
- :choices (mandatory)
|
|
67
|
+
- :case_sensitive
|
|
68
|
+
- Credentials
|
|
69
|
+
- Directory Path
|
|
70
|
+
- :create
|
|
71
|
+
- :exists
|
|
72
|
+
- :executable
|
|
73
|
+
- :readable
|
|
74
|
+
- :writable
|
|
75
|
+
- File Path
|
|
76
|
+
- :create
|
|
77
|
+
- :exists
|
|
78
|
+
- :executable
|
|
79
|
+
- :readable
|
|
80
|
+
- :writable
|
|
81
|
+
- Headers
|
|
82
|
+
- Integer
|
|
83
|
+
- IntegerRange
|
|
84
|
+
- separator (default: '-')
|
|
85
|
+
- MultiChoices
|
|
86
|
+
- choices (mandatory)
|
|
87
|
+
- separator (default: ',')
|
|
88
|
+
- incompatible
|
|
89
|
+
- Positive Integer
|
|
90
|
+
- Path
|
|
91
|
+
- :create
|
|
92
|
+
- :file
|
|
93
|
+
- :directory
|
|
94
|
+
- :exists
|
|
95
|
+
- :executable
|
|
96
|
+
- :readable
|
|
97
|
+
- :writable
|
|
98
|
+
- Proxy
|
|
99
|
+
- :protocols
|
|
100
|
+
- :default_protocol
|
|
101
|
+
- Regexp:
|
|
102
|
+
- :options (See http://ruby-doc.org/core-2.2.1/Regexp.html#method-c-new)
|
|
103
|
+
- SmartList
|
|
104
|
+
- separator (default: ',')
|
|
105
|
+
- String
|
|
106
|
+
- URI
|
|
107
|
+
- :protocols
|
|
108
|
+
- :default_protocol
|
|
109
|
+
- URL
|
|
110
|
+
- :default_protocol
|
data/lib/opt_parse_validator.rb
CHANGED
|
@@ -64,6 +64,31 @@ module OptParseValidator
|
|
|
64
64
|
raise e.is_a?(Error) ? e.class : Error, e.message
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
# @return [ String ] The simplified help (without any of the advanced option/s listed)
|
|
68
|
+
def simple_help
|
|
69
|
+
help = to_s
|
|
70
|
+
|
|
71
|
+
# Removes all advanced help messages
|
|
72
|
+
@opts.select(&:advanced?).each do |opt|
|
|
73
|
+
messages_pattern = //
|
|
74
|
+
|
|
75
|
+
opt.help_messages.each do |msg|
|
|
76
|
+
messages_pattern = /#{messages_pattern}\s*#{Regexp.escape(msg)}/
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
pattern = /\s*#{Regexp.escape(opt.option[0..1].select { |o| o[0] == '-' }.join(', '))}#{messages_pattern}/
|
|
80
|
+
|
|
81
|
+
help.gsub!(pattern, '')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
help
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# @return [ String ] The full help, with the advanced option/s listed
|
|
88
|
+
def full_help
|
|
89
|
+
to_s
|
|
90
|
+
end
|
|
91
|
+
|
|
67
92
|
protected
|
|
68
93
|
|
|
69
94
|
# Ensures the opt given is valid
|
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.16.
|
|
4
|
+
version: 0.0.16.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- WPScanTeam
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-10-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -144,6 +144,8 @@ executables: []
|
|
|
144
144
|
extensions: []
|
|
145
145
|
extra_rdoc_files: []
|
|
146
146
|
files:
|
|
147
|
+
- LICENSE
|
|
148
|
+
- README.md
|
|
147
149
|
- lib/opt_parse_validator.rb
|
|
148
150
|
- lib/opt_parse_validator/errors.rb
|
|
149
151
|
- lib/opt_parse_validator/hacks.rb
|