Merge pull request #1338 from mojombo/abort-with-non-zero-exit-codes

Abort with non-zero exit codes
This commit is contained in:
Parker Moore 2013-07-23 10:59:26 -07:00
commit 8352083bca
2 changed files with 26 additions and 5 deletions

View File

@ -12,7 +12,7 @@ program :name, 'jekyll'
program :version, Jekyll::VERSION
program :description, 'Jekyll is a blog-aware, static site generator in Ruby'
default_command :help
default_command :default
global_option '-s', '--source [DIR]', 'Source directory (defaults to ./)'
global_option '-d', '--destination [DIR]', 'Destination directory (defaults to ./_site)'
@ -33,6 +33,16 @@ def normalize_options(options)
options
end
command :default do |c|
c.action do |args, options|
if args.empty?
command(:help).run
else
Jekyll.logger.abort_with "Invalid command. Use --help for more information"
end
end
end
command :new do |c|
c.syntax = 'jekyll new PATH'
c.description = 'Creates a new Jekyll site scaffold in PATH'

View File

@ -5,7 +5,7 @@ module Jekyll
DEBUG = 0
INFO = 1
WARN = 2
ERROR = 3
ERROR = 3
# Public: Create a new instance of Stevenson, Jekyll's logger
#
@ -22,7 +22,7 @@ module Jekyll
# message - the message detail
#
# Returns nothing
def info(topic, message)
def info(topic, message = nil)
$stdout.puts(message(topic, message)) if log_level <= INFO
end
@ -32,7 +32,7 @@ module Jekyll
# message - the message detail
#
# Returns nothing
def warn(topic, message)
def warn(topic, message = nil)
$stderr.puts(message(topic, message).yellow) if log_level <= WARN
end
@ -42,10 +42,21 @@ module Jekyll
# message - the message detail
#
# Returns nothing
def error(topic, message)
def error(topic, message = nil)
$stderr.puts(message(topic, message).red) if log_level <= ERROR
end
# Public: Print a Jekyll error message to stderr and immediately abort the process
#
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
# message - the message detail (can be omitted)
#
# Returns nothing
def abort_with(topic, message = nil)
error(topic, message)
abort
end
# Public: Build a Jekyll topic method
#
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.