Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a basic show command #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/gel/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ def self.extract_word(arguments)
require_relative "command/stub"
require_relative "command/config"
require_relative "command/shell_setup"
require_relative "command/show"
47 changes: 47 additions & 0 deletions lib/gel/command/show.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

class Gel::Command::Show < Gel::Command
def run(command_line)
mode = :human

until command_line.empty?
case argument = command_line.shift
when "--list"; mode = :list
when "-l"; mode = :list
when "--paths"; mode = :paths
when "-p"; mode = :paths
else
raise "Unknown argument #{argument.inspect}"
end
end

Gel::Environment.activate(output: $stderr)

case mode
when :human
puts "Gems included by the bundle:"
gems.each { |gem|
puts " * #{gem.name} (#{gem.version})"
}
when :list
puts gems.map(&:name)
when :paths
puts gems.map(&:root)
end
end

private
def gems
gems_for(Gel::Environment.gemfile.gems)
end

def gems_for(gems)
# Special handling for bundler since it just returns nil if we try to resolve it
gems.map(&:first).reject { |g| g == 'bundler' }.map { |gem|
current_gem = Gel::Environment.find_gem(gem)
raise "Could not find gem #{gem}, have you successfully run gel install?" unless current_gem

[current_gem, gems_for(current_gem.dependencies)]
}.flatten.uniq(&:name).sort_by(&:name)
end
end