From b807799f24685f5ca6d13a355840928a4a1b479d Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 31 Mar 2017 01:30:59 -0400 Subject: [PATCH] Specify version constraint in subcommand error message. (#5974) Merge pull request 5974 --- exe/jekyll | 4 ++-- lib/jekyll/external.rb | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/exe/jekyll b/exe/jekyll index 3bd37e54..f0f41c93 100755 --- a/exe/jekyll +++ b/exe/jekyll @@ -25,13 +25,13 @@ Mercenary.program(:jekyll) do |p| "Layouts directory (defaults to ./_layouts)" p.option "profile", "--profile", "Generate a Liquid rendering profile" - Jekyll::External.require_if_present(Jekyll::External.blessed_gems) do |g| + Jekyll::External.require_if_present(Jekyll::External.blessed_gems) do |g, ver_constraint| cmd = g.split("-").last p.command(cmd.to_sym) do |c| c.syntax cmd c.action do Jekyll.logger.abort_with "You must install the '#{g}' gem" \ - " to use the 'jekyll #{cmd}' command." + " version #{ver_constraint} to use the 'jekyll #{cmd}' command." end end end diff --git a/lib/jekyll/external.rb b/lib/jekyll/external.rb index 503569db..bdefc798 100644 --- a/lib/jekyll/external.rb +++ b/lib/jekyll/external.rb @@ -23,12 +23,25 @@ module Jekyll require name rescue LoadError Jekyll.logger.debug "Couldn't load #{name}. Skipping." - yield(name) if block_given? + yield(name, version_constraint(name)) if block_given? false end end end + # + # The version constraint required to activate a given gem. + # Usually the gem version requirement is "> 0," because any version + # will do. In the case of jekyll-docs, however, we require the exact + # same version as Jekyll. + # + # Returns a String version constraint in a parseable form for + # RubyGems. + def version_constraint(gem_name) + return "= #{Jekyll::VERSION}" if gem_name.to_s.eql?("jekyll-docs") + "> 0" + end + # # Require a gem or gems. If it's not present, show a very nice error # message that explains everything and is much more helpful than the