Create a default command to run help if there are no arguments but to fail with non-zero exit code if the command is invalid.

Props to @ggilder.
This commit is contained in:
Parker Moore 2013-07-22 10:04:45 +02:00
parent 9e22d23801
commit 5fb13d8047
1 changed files with 11 additions and 1 deletions

View File

@ -12,7 +12,7 @@ program :name, 'jekyll'
program :version, Jekyll::VERSION program :version, Jekyll::VERSION
program :description, 'Jekyll is a blog-aware, static site generator in Ruby' 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 '-s', '--source [DIR]', 'Source directory (defaults to ./)'
global_option '-d', '--destination [DIR]', 'Destination directory (defaults to ./_site)' global_option '-d', '--destination [DIR]', 'Destination directory (defaults to ./_site)'
@ -33,6 +33,16 @@ def normalize_options(options)
options options
end 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| command :new do |c|
c.syntax = 'jekyll new PATH' c.syntax = 'jekyll new PATH'
c.description = 'Creates a new Jekyll site scaffold in PATH' c.description = 'Creates a new Jekyll site scaffold in PATH'