Skip to content
Permalink
Browse files

Merge pull request #78 from sj26/cli-open-command

Second iteration of a `gel open [gem-name]` CLI command
  • Loading branch information...
matthewd committed Aug 6, 2019
2 parents c9270f7 + fe9c676 commit 1cf665313d956243d381ecf361a239ac59039232
Showing with 25 additions and 0 deletions.
  1. +1 −0 lib/gel/command.rb
  2. +24 −0 lib/gel/command/open.rb
@@ -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/open"
@@ -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.
You can’t perform that action at this time.