From a0f449d613f63b173ad51eed33be21af1f29b894 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 6 Aug 2014 21:17:38 -0400 Subject: [PATCH 1/3] Add 'jekyll help' command. Ref: #2695 --- lib/jekyll/commands/help.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/jekyll/commands/help.rb diff --git a/lib/jekyll/commands/help.rb b/lib/jekyll/commands/help.rb new file mode 100644 index 00000000..60c037be --- /dev/null +++ b/lib/jekyll/commands/help.rb @@ -0,0 +1,30 @@ +module Jekyll + module Commands + class Help < Command + class << self + + def init_with_program(prog) + prog.command(:help) do |c| + c.syntax 'help ' + c.description 'Show the help for' + + c.action do |args, _| + if args.empty? + puts prog + else + puts prog.commands[args.first.to_sym] + end + end + end + end + + def usage_message(prog, cmd) + Jekyll.logger.error "Error:", "No command specified." + Jekyll.logger.warn "Usage:", cmd.syntax + Jekyll.logger.info "Valid commands:", prog.commands.keys.join(", ") + end + + end + end + end +end From 23515acc31859e95633fa1498b2fb3edf2846e17 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 6 Aug 2014 21:20:39 -0400 Subject: [PATCH 2/3] Slim down help command. --- lib/jekyll/commands/help.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/jekyll/commands/help.rb b/lib/jekyll/commands/help.rb index 60c037be..b9e79f22 100644 --- a/lib/jekyll/commands/help.rb +++ b/lib/jekyll/commands/help.rb @@ -5,8 +5,8 @@ module Jekyll def init_with_program(prog) prog.command(:help) do |c| - c.syntax 'help ' - c.description 'Show the help for' + c.syntax 'help [subcommand]' + c.description 'Show the help message, optionally for a given subcommand.' c.action do |args, _| if args.empty? @@ -18,12 +18,6 @@ module Jekyll end end - def usage_message(prog, cmd) - Jekyll.logger.error "Error:", "No command specified." - Jekyll.logger.warn "Usage:", cmd.syntax - Jekyll.logger.info "Valid commands:", prog.commands.keys.join(", ") - end - end end end From 939c67222a5739eb435399a03de8374f791e3c93 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 6 Aug 2014 21:28:21 -0400 Subject: [PATCH 3/3] Check to make sure the command is valid. --- lib/jekyll/commands/help.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/commands/help.rb b/lib/jekyll/commands/help.rb index b9e79f22..421d87e5 100644 --- a/lib/jekyll/commands/help.rb +++ b/lib/jekyll/commands/help.rb @@ -9,15 +9,24 @@ module Jekyll c.description 'Show the help message, optionally for a given subcommand.' c.action do |args, _| + cmd = (args.first || "").to_sym if args.empty? puts prog + elsif prog.has_command? cmd + puts prog.commands[cmd] else - puts prog.commands[args.first.to_sym] + invalid_command(prog, cmd) + abort end end end end + def invalid_command(prog, cmd) + Jekyll.logger.error "Error:", "Hmm... we don't know what the '#{cmd}' command is." + Jekyll.logger.info "Valid commands:", prog.commands.keys.join(", ") + end + end end end