Class: Gemview::Commands::Info

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/gemview/commands.rb

Instance Method Summary collapse

Instance Method Details

#call(name:, version: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gemview/commands.rb', line 18

def call(name:, version: nil, **)
  begin
    gem = Gem.find(name: name, version: version)
  rescue Gems::NotFound
    if version
      warn("Error: No gem found with the name '#{name}' and the version '#{version}'")
      exit(1) unless Terminal.confirm(question: "Search for the most recent version?")
      begin
        gem = Gem.find(name: name, version: nil)
      rescue Gems::NotFound
        abort("Error: No gem found with the name: #{name}")
      end
    else
      abort("Error: No gem found with the name: #{name}")
    end
  end
  View.info(gem: gem)
end