class OptParserInternal
this class is only private and helper for main class OptParser
Attributes
options[RW]
Public Class Methods
new()
click to toggle source
# File lib/gitarro/opt_parser.rb, line 131 def initialize @options = {} @options = options.clone if options.any? end
Public Instance Methods
ck_mandatory_option(option)
click to toggle source
# File lib/gitarro/opt_parser.rb, line 143 def ck_mandatory_option(option) return unless @options[option.to_sym].nil? raise_incorrect_syntax("option --#{option} not found") end
option_help(opt)
click to toggle source
option help
# File lib/gitarro/opt_parser.rb, line 158 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)
click to toggle source
# File lib/gitarro/opt_parser.rb, line 149 def parse(opt_parser) parse_options(opt_parser) mandatory_options = %w[repo context test_file] mandatory_options.each { |opt| ck_mandatory_option(opt) } defaults_false defaults_to_text end
raise_incorrect_syntax(msg)
click to toggle source
all this methods are private
# File lib/gitarro/opt_parser.rb, line 137 def raise_incorrect_syntax(msg) puts "Incorrect syntax: #{msg}\n\n" puts 'Use option -h for help' exit 1 end
Private Instance Methods
defaults_false()
click to toggle source
set some default values
# File lib/gitarro/opt_parser.rb, line 179 def defaults_false @options[:force_test] = false if @options[:force_test].nil? @options[:check] = false if @options[:check].nil? @options[:target_url] = '' if @options[:target_url].nil? @options[:https] = false if @options[:https].nil? @options[:noshallow] = false if @options[:noshallow].nil? @options[:changed_since] = -1 if @options[:changed_since].nil? end
defaults_to_text()
click to toggle source
# File lib/gitarro/opt_parser.rb, line 188 def defaults_to_text desc = 'use option -d to set a custom test description.' @options[:description] = desc if @options[:description].nil? @options[:file_type] = 'notype' if @options[:file_type].nil? @options[:git_dir] = '/tmp' if @options[:git_dir].nil? end
parse_options(opt_parser)
click to toggle source
# File lib/gitarro/opt_parser.rb, line 172 def parse_options(opt_parser) opt_parser.parse! rescue OptionParser::ParseError raise_incorrect_syntax($ERROR_INFO.to_s) end