The defaults should mostly work
# File lib/gem2rpm/configuration.rb, line 70 def initialize @options = nil @parser = nil end
# File lib/gem2rpm/configuration.rb, line 92 def macro_for(category) macros[category] ||= '' end
Hash with macros for files categories
# File lib/gem2rpm/configuration.rb, line 83 def macros @_macros ||= DEFAULT_MACROS.dup end
Get options.
# File lib/gem2rpm/configuration.rb, line 101 def options handle_options unless @options @options end
Set the configuration back to default values
# File lib/gem2rpm/configuration.rb, line 76 def reset @_macros = nil @_rules = nil self end
# File lib/gem2rpm/configuration.rb, line 96 def rule_for(category) rules[category] ||= '' end
Hash with rules for file categorization
# File lib/gem2rpm/configuration.rb, line 88 def rules @_rules ||= DEFAULT_RULES.dup end
Creates an option parser.
# File lib/gem2rpm/configuration.rb, line 121 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 109 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 $stderr.puts "#{e}\n\n" $stderr.puts parser exit(1) end
Get parser instance.
# File lib/gem2rpm/configuration.rb, line 127 def parser create_option_parser unless @parser @parser end
# File lib/gem2rpm/configuration.rb, line 132 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 # TODO: This does not belong here. parser.on('--templates', 'List all available templates') do puts 'Available templates in #{Gem2Rpm::Template.default_location}:\n\n' puts Gem2Rpm::Template.list.map do |t| t.gsub(/(.*)\.spec.erb/, '\1') end.join("\n") exit 0 end # TODO: This does not belong here. parser.on('-v', '--version', 'Print gem2rpm\s version and exit') do puts Gem2Rpm::VERSION exit 0 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.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