From 4fe9eecf053eb5d6047011372d8a195e88fb8614 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 11 Dec 2015 14:45:13 -0800 Subject: [PATCH 1/2] For blessed gems, shim their commands so users know how to use them. --- bin/jekyll | 14 ++++++++++---- lib/jekyll/external.rb | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/jekyll b/bin/jekyll index 173a58d3..96e15727 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -6,10 +6,6 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w( .. lib )) require 'jekyll' require 'mercenary' -Jekyll::External.require_if_present( - Jekyll::External.blessed_gems -) - Jekyll::PluginManager.require_from_bundler Jekyll::Deprecator.process(ARGV) @@ -26,6 +22,16 @@ Mercenary.program(:jekyll) do |p| p.option 'layouts_dir', '--layouts DIR', String, '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| + 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." + end + end + end + Jekyll::Command.subclasses.each { |c| c.init_with_program(p) } p.action do |args, _| diff --git a/lib/jekyll/external.rb b/lib/jekyll/external.rb index d213364b..2996d24b 100644 --- a/lib/jekyll/external.rb +++ b/lib/jekyll/external.rb @@ -17,12 +17,13 @@ module Jekyll # # names - a string gem name or array of gem names # - def require_if_present(names) + def require_if_present(names, &block) Array(names).each do |name| begin require name rescue LoadError Jekyll.logger.debug "Couldn't load #{name}. Skipping." + block.call(name) if block false end end From d37de5c8dfdcd10b4a2a48ae3498e954f4327c7e Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 4 Jan 2016 16:17:48 -0800 Subject: [PATCH 2/2] If the subcommand cannot be found, suggest the installation of a gem. --- bin/jekyll | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/jekyll b/bin/jekyll index 96e15727..43364b99 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -40,8 +40,11 @@ Mercenary.program(:jekyll) do |p| puts p abort else - unless p.has_command?(args.first) - Jekyll.logger.abort_with "Invalid command. Use --help for more information" + subcommand = args.first + unless p.has_command? subcommand + Jekyll.logger.abort_with "fatal: 'jekyll #{args.first}' could not" \ + " be found. You may need to install the jekyll-#{args.first} gem" \ + " or a related gem to be able to use this subcommand." end end end