Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Integrate the new bundler man pages with bundle help

  • Loading branch information...
commit 3d146785582a10cb5c11a792a03f50b8611109c8 1 parent a2f4715
Carl Lerche authored
View
17 Rakefile
@@ -28,7 +28,7 @@ begin
t.spec_opts = %w(-fs --color)
t.warning = true
end
- task :spec
+ task :spec => :build
namespace :spec do
task :sudo do
@@ -146,7 +146,7 @@ else
Rake::GemPackageTask.new(gemspec) do |pkg|
pkg.gem_spec = gemspec
end
- task :gem => :gemspec
+ task :gem => [:build, :gemspec]
end
desc "install the gem locally"
@@ -159,5 +159,14 @@ task :gemspec do
gemspec.validate
end
-task :package => :gemspec
-task :default => :spec
+desc "Build the gem"
+task :gem => [:gemspec, :build] do
+ mkdir_p "pkg"
+ sh "gem build bundler.gemspec"
+ mv "#{gemspec.full_name}.gem pkg"
+end
+
+desc "Install bundler"
+task :install => :gem do
+ sh "gem install pkg/#{gemspec.full_name}.gem"
+end
View
8 lib/bundler.rb
@@ -45,6 +45,11 @@ class DslError < BundlerError; status_code(15) ; end
class ProductionError < BundlerError; status_code(16) ; end
class InvalidOption < DslError ; end
+
+ WINDOWS = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
+ NULL = WINDOWS ? "NUL" : "/dev/null"
+
+
class VersionConflict < BundlerError
attr_reader :conflicts
@@ -186,9 +191,6 @@ def default_lockfile
SharedHelpers.default_lockfile
end
- WINDOWS = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
- NULL = WINDOWS ? "NUL" : "/dev/null"
-
def requires_sudo?
path = bundle_path
path = path.parent until path.exist?
View
37 lib/bundler/cli.rb
@@ -23,6 +23,38 @@ def initialize(*)
default_task :install
class_option "no-color", :type => :boolean, :banner => "Disable colorization in output"
+ def help(cli = nil)
+ case cli
+ when "gemfile" then command = "gemfile.5"
+ when nil then command = "bundle"
+ else command = "bundle-#{command}"
+ end
+
+ manpages = %w(
+ bundle
+ bundle-config
+ bundle-exec
+ bundle-install
+ bundle-package
+ bundle-update
+ gemfile.5)
+
+ if manpages.include?(command)
+ root = File.expand_path("../man", __FILE__)
+
+ if have_groff?
+ groff = "groff -Wall -mtty-char -mandoc -Tascii"
+ pager = ENV['MANPAGER'] || ENV['PAGER'] || 'more'
+
+ Kernel.exec "#{groff} #{root}/#{command} | #{pager}"
+ else
+ puts File.read("#{root}/#{command}.txt")
+ end
+ else
+ super
+ end
+ end
+
desc "init", "Generates a Gemfile into the current working directory"
long_desc <<-D
Init generates a default Gemfile in the current working directory. When adding a
@@ -449,6 +481,11 @@ def self.source_root
private
+ def have_groff?
+ `which groff 2>#{NULL}`
+ $? == 0
+ end
+
def locate_gem(name)
spec = Bundler.load.specs.find{|s| s.name == name }
raise GemNotFound, "Could not find gem '#{name}' in the current bundle." unless spec
View
28 spec/other/help_spec.rb
@@ -7,4 +7,30 @@
bundle "help", :expect_err => true
err.should == "Please remove older versions of bundler. This can be done by running `gem cleanup bundler`."
end
-end
+
+ it "uses groff when available" do
+ fake_groff!
+
+ bundle "help gemfile"
+ out.should == %|["-Wall", "-mtty-char", "-mandoc", "-Tascii", "#{root}/lib/bundler/man/gemfile.5"]|
+ end
+
+ it "prefixes bundle commands with bundle- when finding the groff files" do
+ fake_groff!
+
+ bundle "help install"
+ out.should == %|["-Wall", "-mtty-char", "-mandoc", "-Tascii", "#{root}/lib/bundler/man/bundle-install"]|
+ end
+
+ it "simply outputs the txt file when there is no groff on the path" do
+ kill_path!
+
+ bundle "help install"
+ out.should =~ /BUNDLE-INSTALL/
+ end
+
+ it "still outputs the old help for commands that do not have man pages yet" do
+ bundle "help check"
+ out.should include("Check searches the local machine")
+ end
+end
View
13 spec/support/helpers.rb
@@ -168,6 +168,19 @@ def break_git!
ENV["PATH"] = "#{tmp("broken_path")}:#{ENV["PATH"]}"
end
+ def fake_groff!
+ FileUtils.mkdir_p(tmp("fake_groff"))
+ File.open(tmp("fake_groff/groff"), "w", 0755) do |f|
+ f.puts "#!/usr/bin/env ruby\nputs ARGV.inspect\n"
+ end
+
+ ENV["PATH"] = "#{tmp("fake_groff")}:#{ENV["PATH"]}"
+ end
+
+ def kill_path!
+ ENV["PATH"] = ""
+ end
+
def system_gems(*gems)
gems = gems.flatten

1 comment on commit 3d14678

@wincent

Nice way of including man pages in a Ruby gem.

Please sign in to comment.
Something went wrong with that request. Please try again.