Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added --editor option to open generated gemspec in editor #2224

Merged
merged 1 commit into from

3 participants

@ndbroadbent

Adds an --editor option for the bundle gem command, to open the generated gemspec in the user's editor. Comes with CHANGELOG entry and test.

Similar to rails/rails#8553

@rohit
Collaborator

I personally don't like this and think it would not be used much. But if this is desirable by the maintainers maybe a better option name like --editspec? I don't think --editor is descriptive enough.

Oh btw not to nag but your other PR needs some work: #2143 :grin:

@rohit
Collaborator

@indirect Are you keen on merging this PR? :)

@indirect
Owner

I think it makes sense as an option named --edit. I'm not totally sure how bundle gem foo --edit is more convenient than bundle gem foo↩f⇥↩, though. What's the argument in favor?

@ndbroadbent

I've updated the PR with --edit instead of --editor. What do you mean by bundle gem foo↩f⇥↩? It looks like your suggestion cds into the gem directory, but my PR opens the generated gemspec in your text editor so you can edit authors, homepage, summary, description, etc.

@indirect
Owner

Hmm, maybe the special characters aren't visible. I just mean that it's around the same number of typed characters to tab-complete the name of the gemspec and open it than it is to add --edit to the end, so why is an edit option better? :)

@ndbroadbent

Ah, I see. Well, I guess the -e shortcut is a bit shorter. The other solution is just to add this to my .bashrc:

bgem() { bundle gem "$1"; sublime-text-2 "$1/$1.gemspec"; }

So yeah, not the most critical feature, but thought other people might find the editor option useful :)

@indirect
Owner

Yeah, -e seems nice. I buy it. Thanks for the patch!

@indirect indirect merged commit 7cdf823 into bundler:master
@ndbroadbent

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 1 deletion.
  1. +1 −0  CHANGELOG.md
  2. +11 −1 lib/bundler/cli.rb
  3. +10 −0 spec/other/newgem_spec.rb
View
1  CHANGELOG.md
@@ -5,6 +5,7 @@ Features:
- pushing gems during `rake release` can be disabled (@trans)
- installing gems with `rake install` is much faster (@utkarshkukreti)
- added platforms :ruby_20 and :mri_20, since the ABI has changed
+ - added '--edit' option to open generated gemspec in editor
Bugfixes:
View
12 lib/bundler/cli.rb
@@ -601,6 +601,11 @@ def viz
desc "gem GEM", "Creates a skeleton for creating a rubygem"
method_option :bin, :type => :boolean, :default => false, :aliases => '-b', :banner => "Generate a binary for your library."
method_option :test, :type => :string, :default => 'rspec', :aliases => '-t', :banner => "Generate a test directory for your library: 'rspec' is the default, but 'minitest' is also supported."
+ method_option :edit, :type => :string, :aliases => "-e",
+ :lazy_default => [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? },
+ :required => false, :banner => "/path/to/your/editor",
+ :desc => "Open generated gemspec in the specified editor (defaults to $EDITOR or $BUNDLER_EDITOR)"
+
def gem(name)
name = name.chomp("/") # remove trailing slash if present
namespaced_path = name.tr('-', '/')
@@ -618,12 +623,13 @@ def gem(name)
:author => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
:email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email
}
+ gemspec_dest = File.join(target, "#{name}.gemspec")
template(File.join("newgem/Gemfile.tt"), File.join(target, "Gemfile"), opts)
template(File.join("newgem/Rakefile.tt"), File.join(target, "Rakefile"), opts)
template(File.join("newgem/LICENSE.txt.tt"), File.join(target, "LICENSE.txt"), opts)
template(File.join("newgem/README.md.tt"), File.join(target, "README.md"), opts)
template(File.join("newgem/gitignore.tt"), File.join(target, ".gitignore"), opts)
- template(File.join("newgem/newgem.gemspec.tt"), File.join(target, "#{name}.gemspec"), opts)
+ template(File.join("newgem/newgem.gemspec.tt"), gemspec_dest, opts)
template(File.join("newgem/lib/newgem.rb.tt"), File.join(target, "lib/#{namespaced_path}.rb"), opts)
template(File.join("newgem/lib/newgem/version.rb.tt"), File.join(target, "lib/#{namespaced_path}/version.rb"), opts)
if options[:bin]
@@ -640,6 +646,10 @@ def gem(name)
end
Bundler.ui.info "Initializating git repo in #{target}"
Dir.chdir(target) { `git init`; `git add .` }
+
+ if options[:edit]
+ run("#{options["edit"]} \"#{gemspec_dest}\"") # Open gemspec in editor
+ end
end
def self.source_root
View
10 spec/other/newgem_spec.rb
@@ -179,6 +179,16 @@
expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist
end
end
+
+ context "--edit option" do
+ it "opens the generated gemspec in the user's text editor" do
+ reset!
+ in_app_root
+ output = bundle "gem #{gem_name} --edit=echo"
+ gemspec_path = File.join(Dir.pwd, gem_name, "#{gem_name}.gemspec")
+ expect(output).to include("echo \"#{gemspec_path}\"")
+ end
+ end
end
context "gem naming with dashed" do
Something went wrong with that request. Please try again.