lib/lapidarius/cli.rb in lapidarius-3.3.0 vs lib/lapidarius/cli.rb in lapidarius-3.4.0

- old
+ new

@@ -3,42 +3,45 @@ module Lapidarius class CLI HELP_FLAGS = %w[-h --help] COL_WIDTH = 23 + attr_reader :name, :version + def initialize(input, - pipe = STDOUT, + out = STDOUT, command = Command, cutter = Cutter, tree = Tree) - @input = input.to_s.strip - @pipe = pipe - @cutter = cutter.new(@input, command) + @name, @version = Array(input).map(&:strip) + @out = out + @cutter = cutter.new(name: @name, cmd_klass: command, version: @version) @tree = tree end def call - @pipe.puts output + @out.puts output end private def output return help if help? - return if @input.empty? + return unless @name gem = @cutter.call - @tree::new(gem).out + @tree::new(gem).to_s rescue Gem::NotInstalledError => e - e.message.sub("specified", %Q{"#{@input}"}) + e.message end private def help? - HELP_FLAGS.include?(@input) + HELP_FLAGS.include?(@name) end private def help [].tap do |h| - h << %q{Usage: lapidarius sinatra} + h << %q{Usage: lapidarius <name> <version>} h << " %-#{COL_WIDTH}s Print this help" % "-h --help" - h << " %-#{COL_WIDTH}s Gem's name to cut" % "<gem-name>" + h << " %-#{COL_WIDTH}s Gem's name to cut" % "<name>" + h << " %-#{COL_WIDTH}s Gem's version to cut" % "<version>" end end end end