Class: OptParseValidator::OptParser
- Inherits:
-
OptionParser
- Object
- OptionParser
- OptParseValidator::OptParser
- Defined in:
- lib/opt_parse_validator.rb
Overview
Validator
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#symbols_used ⇒ Object
readonly
Returns the value of attribute symbols_used.
Instance Method Summary collapse
-
#add(*options) ⇒ Self
For chaining #new.add.results.
-
#full_help ⇒ String
The full help, with the advanced option/s listed.
-
#initialize(banner = nil, width = 32, indent = ' ' * 4) ⇒ OptParser
constructor
A new instance of OptParser.
- #options_files ⇒ OptParseValidator::OptionsFiles
- #results(argv = default_argv) ⇒ Hash
-
#simple_help ⇒ String
The simplified help (without any of the advanced option/s listed).
Constructor Details
#initialize(banner = nil, width = 32, indent = ' ' * 4) ⇒ OptParser
Returns a new instance of OptParser.
21 22 23 24 25 26 27 |
# File 'lib/opt_parse_validator.rb', line 21 def initialize( = nil, width = 32, indent = ' ' * 4) @results = {} @symbols_used = [] @opts = [] super(, width, indent) end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
19 20 21 |
# File 'lib/opt_parse_validator.rb', line 19 def opts @opts end |
#symbols_used ⇒ Object (readonly)
Returns the value of attribute symbols_used.
19 20 21 |
# File 'lib/opt_parse_validator.rb', line 19 def symbols_used @symbols_used end |
Instance Method Details
#add(*options) ⇒ Self
Returns For chaining #new.add.results.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/opt_parse_validator.rb', line 37 def add(*) .each do |option| check_option(option) @opts << option @symbols_used << option.to_sym # Set the default option value if it exists # The default value is not validated as it is provided by devs # and should be set to the correct format/value directly @results[option.to_sym] = option.default unless option.default.nil? register_callback(option) end self end |
#full_help ⇒ String
Returns The full help, with the advanced option/s listed.
88 89 90 |
# File 'lib/opt_parse_validator.rb', line 88 def full_help to_s end |
#options_files ⇒ OptParseValidator::OptionsFiles
30 31 32 |
# File 'lib/opt_parse_validator.rb', line 30 def @options_files ||= OptionsFiles.new end |
#results(argv = default_argv) ⇒ Hash
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/opt_parse_validator.rb', line 56 def results(argv = default_argv) parse!(argv) post_processing @results rescue StandardError => e # Raise it as an OptParseValidator::Error if not already one raise e.is_a?(Error) ? e.class : Error, e. end |
#simple_help ⇒ String
Returns The simplified help (without any of the advanced option/s listed).
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/opt_parse_validator.rb', line 68 def simple_help help = to_s # Removes all advanced help messages @opts.select(&:advanced?).each do |opt| = // opt..each do |msg| = /#{}\s*#{Regexp.escape(msg)}/ end pattern = /\s*#{Regexp.escape(opt.option[0..1].select { |o| o[0] == '-' }.join(', '))}#{}/ help.gsub!(pattern, '') end help end |