Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from sj26/cli-open-command
Second iteration of a `gel open [gem-name]` CLI command
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |