From 9d5f171347b20d443436d0b2bf765a533969e6a2 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 1 Oct 2014 17:27:48 +0100 Subject: fixup! import: Put Ruby option parsing into base class --- import/rubygems.to_chunk | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/import/rubygems.to_chunk b/import/rubygems.to_chunk index cc21fb83..c90cda23 100755 --- a/import/rubygems.to_chunk +++ b/import/rubygems.to_chunk @@ -19,19 +19,8 @@ require 'bundler' -require 'optparse' - require_relative 'importer_base' -DESCRIPTION = <<-END -This tool reads the Gemfile and optionally the Gemfile.lock from a Ruby project -source tree in SOURCE_DIR. It outputs a chunk morphology for GEM_NAME on -stdout. If VERSION is supplied, it is used to check that the build instructions -will produce the expected version of the Gem. - -It is intended for use with the `baserock-import` tool. -END - class << Bundler def default_gemfile # This is a hack to make things not crash when there's no Gemfile @@ -44,6 +33,17 @@ def spec_is_from_current_source_tree(spec) spec.source.path.fnmatch?('.') end +BANNER = "Usage: rubygems.to_chunk SOURCE_DIR GEM_NAME [VERSION]" + +DESCRIPTION = <<-END +This tool reads the Gemfile and optionally the Gemfile.lock from a Ruby project +source tree in SOURCE_DIR. It outputs a chunk morphology for GEM_NAME on +stdout. If VERSION is supplied, it is used to check that the build instructions +will produce the expected version of the Gem. + +It is intended for use with the `baserock-import` tool. +END + class RubyGemChunkMorphologyGenerator < Importer::Base def initialize local_data = YAML.load_file("rubygems.yaml") @@ -51,15 +51,7 @@ class RubyGemChunkMorphologyGenerator < Importer::Base end def parse_options(arguments) - opts = OptionParser.new - - opts.banner = "Usage: rubygems.to_chunk SOURCE_DIR GEM_NAME [VERSION]" - - opts.on('-?', '--help', 'print this help') do - puts opts - print "\n", DESCRIPTION - exit 1 - end + opts = create_option_parser(BANNER, DESCRIPTION) parsed_arguments = opts.parse!(arguments) -- cgit v1.2.1