The defaults should mostly work
# File lib/gem2rpm/configuration.rb, line 85 def initialize @options = nil @parser = nil end
# File lib/gem2rpm/configuration.rb, line 107 def macro_for(category) macros[category] ||= '' end
Hash with macros for files categories
# File lib/gem2rpm/configuration.rb, line 98 def macros @_macros ||= DEFAULT_MACROS.dup end
Get options.
# File lib/gem2rpm/configuration.rb, line 116 def options handle_options unless @options @options end
Set the configuration back to default values
# File lib/gem2rpm/configuration.rb, line 91 def reset @_macros = nil @_rules = nil self end
# File lib/gem2rpm/configuration.rb, line 111 def rule_for(category) rules[category] ||= '' end
Hash with rules for file categorization
# File lib/gem2rpm/configuration.rb, line 103 def rules @_rules ||= DEFAULT_RULES.dup end
Creates an option parser.
# File lib/gem2rpm/configuration.rb, line 135 def create_option_parser @parser = OptionParser.new setup_parser_options end
Handles list of given options. Use ARGV by default.
# File lib/gem2rpm/configuration.rb, line 124 def handle_options(args = ARGV) @options = Marshal.load Marshal.dump DEFAULT_OPTIONS # deep copy parser.parse!(args) @options[:args] = args # TODO: Refactor, this is probably not the best palce. rescue OptionParser::InvalidOption => e message = "#{e}\n\n#{parser}\n" fail(InvalidOption, message) end
Get parser instance.
# File lib/gem2rpm/configuration.rb, line 141 def parser create_option_parser unless @parser @parser end
# File lib/gem2rpm/configuration.rb, line 146 def setup_parser_options parser.banner = "Usage: #{$PROGRAM_NAME} [OPTIONS] GEM" parser.separator(' Convert Ruby gems to source RPMs and specfiles.') parser.separator(' Uses a template to generate the RPM specfile') parser.separator(' from the gem specification.') parser.separator('') parser.separator(' Options:') parser.on('-T', '--current-template', 'Print the current template') do options[:print_template_file] = true end parser.on('-t', '--template TEMPLATE', 'Use TEMPLATE for the specfile') do |val| options[:template_file] = val end parser.on('--templates', 'List all available templates') do options[:templates] = true end parser.on('-v', '--version', 'Print gem2rpm\s version and exit') do options[:version] = true end parser.on('-o', '--output FILE', 'Send the specfile to FILE') do |val| options[:output_file] = val end parser.on('-s', '--srpm', 'Create a source RPM') do options[:srpm] = true end parser.on('-l', '--local', "Do not retrieve Gem information over #{' ' * 22} the network. Use on disconnected machines") do options[:local] = true end parser.on('-d', '--dependencies', 'Print the dependencies of the gem') do options[:deps] = true end parser.on('-n', '--nongem', 'Generate a subpackage for non-gem use') do options[:nongem] = true end parser.on('--no-doc', 'Disable document subpackage') do options[:doc_subpackage] = false end parser.on('--fetch', 'Fetch the gem from rubygems.org') do options[:fetch] = true end parser.on('-C', '--directory DIR', 'Change to directory DIR') do |val| options[:directory] = val end parser.separator('') parser.separator(' Arguments:') parser.separator(' GEM The path to the locally stored gem package file or the name') parser.separator(' of the gem when using --fetch.') parser.separator('') end