summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
authoryoka <jesse.ikonen@gmail.com>2022-12-22 08:39:00 +0200
committergit <svn-admin@ruby-lang.org>2023-01-04 13:13:19 +0000
commit87c17a141dc4491abf5282d164f2cba13ade18c4 (patch)
tree2c296503f3d5257210e9a61c602ae22fc1148429 /lib/bundler
parent3d6500ee6e3676979d5199dc7b5feab0d15235de (diff)
[rubygems/rubygems] Enhance bundle open with --path option
https://github.com/rubygems/rubygems/commit/3bf8e59304
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/cli.rb1
-rw-r--r--lib/bundler/cli/open.rb9
-rw-r--r--lib/bundler/man/bundle-open.122
-rw-r--r--lib/bundler/man/bundle-open.1.ronn10
4 files changed, 36 insertions, 6 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 6745740f11..3f8d0bd0e6 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -509,6 +509,7 @@ module Bundler
subcommand "config", Config
desc "open GEM", "Opens the source directory of the given bundled gem"
+ method_option "path", :type => :string, :banner => "Open relative path of the gem source."
def open(name)
require_relative "cli/open"
Open.new(options, name).run
diff --git a/lib/bundler/cli/open.rb b/lib/bundler/cli/open.rb
index ea504344f3..ebd86fd4b1 100644
--- a/lib/bundler/cli/open.rb
+++ b/lib/bundler/cli/open.rb
@@ -2,10 +2,11 @@
module Bundler
class CLI::Open
- attr_reader :options, :name
+ attr_reader :options, :name, :path
def initialize(options, name)
@options = options
@name = name
+ @path = options[:path] unless options[:path].nil?
end
def run
@@ -15,10 +16,10 @@ module Bundler
if spec.default_gem?
Bundler.ui.info "Unable to open #{name} because it's a default gem, so the directory it would normally be installed to does not exist."
else
- path = spec.full_gem_path
- Dir.chdir(path) do
+ root_path = spec.full_gem_path
+ Dir.chdir(root_path) do
require "shellwords"
- command = Shellwords.split(editor) + [path]
+ command = Shellwords.split(editor) << File.join([root_path, path].compact)
Bundler.with_original_env do
system(*command)
end || Bundler.ui.info("Could not run '#{command.join(" ")}'")
diff --git a/lib/bundler/man/bundle-open.1 b/lib/bundler/man/bundle-open.1
index a3014f34a8..c831bf9ce9 100644
--- a/lib/bundler/man/bundle-open.1
+++ b/lib/bundler/man/bundle-open.1
@@ -7,7 +7,7 @@
\fBbundle\-open\fR \- Opens the source directory for a gem in your bundle
.
.SH "SYNOPSIS"
-\fBbundle open\fR [GEM]
+\fBbundle open\fR [GEM] [\-\-path=PATH]
.
.SH "DESCRIPTION"
Opens the source directory of the provided GEM in your editor\.
@@ -30,3 +30,23 @@ bundle open \'rack\'
.
.P
Will open the source directory for the \'rack\' gem in your bundle\.
+.
+.IP "" 4
+.
+.nf
+
+bundle open \'rack\' \-\-path \'README\.md\'
+.
+.fi
+.
+.IP "" 0
+.
+.P
+Will open the README\.md file of the \'rack\' gem source in your bundle\.
+.
+.SH "OPTIONS"
+.
+.TP
+\fB\-\-path\fR
+Specify GEM source relative path to open\.
+
diff --git a/lib/bundler/man/bundle-open.1.ronn b/lib/bundler/man/bundle-open.1.ronn
index 497beac93f..a857f3a965 100644
--- a/lib/bundler/man/bundle-open.1.ronn
+++ b/lib/bundler/man/bundle-open.1.ronn
@@ -3,7 +3,7 @@ bundle-open(1) -- Opens the source directory for a gem in your bundle
## SYNOPSIS
-`bundle open` [GEM]
+`bundle open` [GEM] [--path=PATH]
## DESCRIPTION
@@ -17,3 +17,11 @@ Example:
bundle open 'rack'
Will open the source directory for the 'rack' gem in your bundle.
+
+ bundle open 'rack' --path 'README.md'
+
+Will open the README.md file of the 'rack' gem source in your bundle.
+
+## OPTIONS
+* `--path`:
+ Specify GEM source relative path to open.