Class: OptParserInternal

Inherits:
Object
  • Object
show all
Includes:
MandatoryOptions, OptionalOptions
Defined in:
lib/gitarro/opt_parser.rb

Overview

this class is only private and helper for main class OptParser

Direct Known Subclasses

OptParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionalOptions

#changed_since, #check_opt, #desc_opt, #file_opt, #https_opt, #optional_options, #pr_number, #url_opt

Methods included from MandatoryOptions

#context_opt, #git_opt, #mandatory_options, #repo_opt, #test_opt

Constructor Details

#initializeOptParserInternal



111
112
113
114
# File 'lib/gitarro/opt_parser.rb', line 111

def initialize
  @options = {}
  @options = options.clone if options.any?
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



110
111
112
# File 'lib/gitarro/opt_parser.rb', line 110

def options
  @options
end

Instance Method Details

#ck_mandatory_option(option) ⇒ Object



123
124
125
126
# File 'lib/gitarro/opt_parser.rb', line 123

def ck_mandatory_option(option)
  return unless @options[option.to_sym].nil?
  raise_incorrect_syntax("option --#{option} not found")
end

#option_help(opt) ⇒ Object

option help



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/gitarro/opt_parser.rb', line 137

def option_help(opt)
  opt.separator "\n Help:"
  opt.on('-h', '--help', 'help') do
    opt.separator " \n Example: gitarro.rb -r " \
                  "openSUSE/gitarro -c 'python-test " \
                  "-d 'someCoolTest' -g /tmp/pr-ruby01/ -t /tmp/test.sh "\
                  "-f '.py'"
    puts @opt_parser
    exit 0
  end
end

#parse(opt_parser) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/gitarro/opt_parser.rb', line 128

def parse(opt_parser)
  parse_options(opt_parser)
  mandatory_options = %w[repo context test_file git_dir]
  mandatory_options.each { |opt| ck_mandatory_option(opt) }
  defaults_false
  defaults_to_text
end

#raise_incorrect_syntax(msg) ⇒ Object

all this methods are private



117
118
119
120
121
# File 'lib/gitarro/opt_parser.rb', line 117

def raise_incorrect_syntax(msg)
  puts "Incorrect syntax: #{msg}\n\n"
  puts 'Use option -h for help'
  exit 1
end