lib/gem2rpm/configuration.rb in gem2rpm-0.11.3 vs lib/gem2rpm/configuration.rb in gem2rpm-1.0.0
- old
+ new
@@ -1,31 +1,39 @@
+require 'optparse'
require 'singleton'
module Gem2Rpm
class Configuration
include Singleton
+ class InvalidOption < Exception; end
+
+ CURRENT_DIR = Dir.pwd
+
DEFAULT_OPTIONS = {
:print_template_file => nil,
:template_file => nil,
+ :templates => false,
+ :version => false,
:output_file => nil,
:local => false,
:srpm => false,
:deps => false,
:nongem => false,
:doc_subpackage => true,
:fetch => false,
- }
+ :directory => CURRENT_DIR,
+ }.freeze
# The defaults should mostly work
DEFAULT_MACROS = {
:instdir => '%{gem_instdir}',
:libdir => '%{gem_libdir}',
:doc => '%doc',
:license => '%license',
:ignore => '%exclude'
- }
+ }.freeze
DEFAULT_RULES = {
:doc => [
/\/?CHANGELOG.*/i,
/\/?CONTRIBUTING.*/i,
@@ -38,36 +46,41 @@
'NEWS',
],
:license => [
/\/?MIT/,
/\/?GPLv[0-9]+/,
- /\/?.*LICEN(C|S)E/,
+ /\/?.*LICEN(C|S)E/i,
/\/?COPYING/,
],
:ignore => [
'.gemtest',
'.gitignore',
'.travis.yml',
'.yardopts',
+ '.rspec',
'.rvmrc',
'.rubocop.yml',
/^\..*rc$/i,
+ /\/?.*\.gemspec$/,
],
+ :test => [
+ '.rspec',
+ 'cucumber.yml',
+ /^features.*/,
+ /^r?spec.*/,
+ /^tests?/,
+ ],
# Other files including test files that are not required for
# runtime and therefore currently included in -doc
:misc => [
- /.*.gemspec/,
/Gemfile.*/,
'Rakefile',
'rakefile.rb',
'Vagrantfile',
- /^spec.*/,
- /^rspec.*/,
- /^test(s|)/,
/^examples.*/,
]
- }
+ }.freeze
def initialize
@options = nil
@parser = nil
end
@@ -110,13 +123,12 @@
@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)
+ message = "#{e}\n\n#{parser}\n"
+ fail(InvalidOption, message)
end
# Creates an option parser.
def create_option_parser
@parser = OptionParser.new
@@ -146,23 +158,16 @@
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
+ options[:templates] = true
end
- # TODO: This does not belong here.
parser.on('-v', '--version', 'Print gem2rpm\'s version and exit') do
- puts Gem2Rpm::VERSION
- exit 0
+ options[:version] = true
end
parser.on('-o', '--output FILE', 'Send the specfile to FILE') do |val|
options[:output_file] = val
end
@@ -188,9 +193,13 @@
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:')