Skip to content

Commit

Permalink
Merge pull request #78 from sj26/cli-open-command
Browse files Browse the repository at this point in the history
Second iteration of a `gel open [gem-name]` CLI command
  • Loading branch information
matthewd committed Aug 6, 2019
2 parents c9270f7 + fe9c676 commit 1cf6653
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/gel/command.rb
Expand Up @@ -84,3 +84,4 @@ def self.extract_word(arguments)
require_relative "command/stub" require_relative "command/stub"
require_relative "command/config" require_relative "command/config"
require_relative "command/shell_setup" require_relative "command/shell_setup"
require_relative "command/open"
24 changes: 24 additions & 0 deletions lib/gel/command/open.rb
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class Gel::Command::Open < Gel::Command
def run(command_line)
require "shellwords"

raise "Please provide the name of a gem to open in your editor" if command_line.empty?
raise "Too many arguments, only 1 gem name is supported" if command_line.length > 1
gem_name = command_line.shift

editor = ENV.fetch("GEL_EDITOR", ENV["EDITOR"])
raise "An editor must be set using either $GEL_EDITOR or $EDITOR" unless editor

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

found_gem = Gel::Environment.find_gem(gem_name)
raise "Can't find gem `#{gem_name}`" unless found_gem

command = [*Shellwords.split(editor), found_gem.root]
Dir.chdir(found_gem.root) do
exec(*command)
end
end
end

0 comments on commit 1cf6653

Please sign in to comment.