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.
- #config_files ⇒ OptParseValidator::ConfigFilesLoaderMerger
-
#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.
- #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.
23 24 25 26 27 28 29 |
# File 'lib/opt_parse_validator.rb', line 23 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.
21 22 23 |
# File 'lib/opt_parse_validator.rb', line 21 def opts @opts end |
#symbols_used ⇒ Object (readonly)
Returns the value of attribute symbols_used.
21 22 23 |
# File 'lib/opt_parse_validator.rb', line 21 def symbols_used @symbols_used end |
Instance Method Details
#add(*options) ⇒ Self
Returns For chaining #new.add.results.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/opt_parse_validator.rb', line 39 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 |
#config_files ⇒ OptParseValidator::ConfigFilesLoaderMerger
32 33 34 |
# File 'lib/opt_parse_validator.rb', line 32 def config_files @config_files ||= ConfigFilesLoaderMerger.new end |
#full_help ⇒ String
Returns The full help, with the advanced option/s listed.
90 91 92 |
# File 'lib/opt_parse_validator.rb', line 90 def full_help to_s end |
#results(argv = default_argv) ⇒ Hash
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/opt_parse_validator.rb', line 58 def results(argv = default_argv) load_config_files 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).
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/opt_parse_validator.rb', line 70 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 |