Sha256: 5a6da886554978ac3bdc0f25a9944b24dc68ba2e15f241571074c05147ac936e

Contents?: true

Size: 1.52 KB

Versions: 16

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Gemsmith
  module Helpers
    # Command Line Interface (CLI) helpers for the CLI class.
    module CLI
      module_function

      def print_gems gems
        say "Multiple versions found:\n\n"

        gems.each.with_index do |spec, index|
          say "#{index + 1}. #{spec.name} #{spec.version.version}"
        end

        say "q. Quit.\n\n"
      end

      # :reek:FeatureEnvy
      # :reek:TooManyStatements
      def pick_gem gems, name
        answer = ask "Enter selection:"
        return if answer == "q"

        answer = answer.to_i

        if (1..gems.size).cover?(answer)
          Gem::Specification.find name, gems[answer - 1].version.version
        else
          say_status :error, "Invalid option: #{answer}", :red
          nil
        end
      end

      def inspect_gem specification, method
        return unless specification
        Gem::Inspector.new.public_send method, Gem::Specification.new(specification.spec_file)
      rescue Versionaire::Errors::Conversion => error
        say_status :error, error.message, :red
      end

      # :reek:TooManyStatements
      def process_gem name, method
        specs = Gem::Specification.find_all name
        spec_count = specs.size

        if spec_count == 1
          inspect_gem specs.first, method
        elsif spec_count > 1
          print_gems specs
          inspect_gem pick_gem(specs, name), method
        else
          say_status(:error, "Unable to find gem: #{name}.", :red) and ""
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
gemsmith-12.3.0 lib/gemsmith/helpers/cli.rb
gemsmith-12.2.0 lib/gemsmith/helpers/cli.rb
gemsmith-12.1.0 lib/gemsmith/helpers/cli.rb
gemsmith-12.0.0 lib/gemsmith/helpers/cli.rb
gemsmith-11.3.0 lib/gemsmith/helpers/cli.rb
gemsmith-11.2.0 lib/gemsmith/helpers/cli.rb
gemsmith-11.1.0 lib/gemsmith/helpers/cli.rb
gemsmith-11.0.1 lib/gemsmith/helpers/cli.rb
gemsmith-11.0.0 lib/gemsmith/helpers/cli.rb
gemsmith-10.4.2 lib/gemsmith/helpers/cli.rb
gemsmith-10.4.1 lib/gemsmith/helpers/cli.rb
gemsmith-10.4.0 lib/gemsmith/helpers/cli.rb
gemsmith-10.3.0 lib/gemsmith/helpers/cli.rb
gemsmith-10.2.0 lib/gemsmith/helpers/cli.rb
gemsmith-10.1.0 lib/gemsmith/helpers/cli.rb
gemsmith-10.0.0 lib/gemsmith/helpers/cli.rb