| Class | Vcs::OptionController |
| In: |
lib/vcs/vcs.rb
|
| Parent: | Object |
| option_parser | [R] | |
| options | [R] | |
| switches | [R] | |
| vcs_name | [R] |
# File lib/vcs/vcs.rb, line 266 def initialize ( aVcsClass, aString ) Vcs.logger.debug { "Creating an option_controller for #{aVcsClass}..." } @switches = [] @switches_finder = {} aString.each_line do |line| next if line.blank? switch = Switch.new(line) @switches << switch @switches_finder[switch.main] = switch switch.aliases.each do |al| @switches_finder[al] = switch end end @option_parser = OptionParser.new do |o| o.banner = "Type '#{$0} help' for usage." o.separator '' @switches.each do |switch| o.on(*switch.to_a_for_option_parser) do |a, *b| raise unless b.empty? options[switch.to_sym] = a end end end Vcs.logger.debug { @option_parser.to_s } end
# File lib/vcs/vcs.rb, line 292 def parse ( argv ) @options = {} [@options, @option_parser.parse(argv)] end
# File lib/vcs/vcs.rb, line 301 def to_strings ( options ) pre, post = [], [] options.each do |k, v| sw = (k.to_s.size == 1)? "-#{k}" : ('--' + k.to_s.gsub('_', '-')) sw.gsub!(/^--/, '--no-') if v == false switch = find sw logger.warn { "Unknown switch: #{sw}" } if switch.nil? result = (switch and switch.pre?)? pre : post result << (switch || sw).to_s result << v.to_s if (v != true) and (v != false) end [pre, post] end