Skip to content

Commit

Permalink
Added exception handling to display a user friendly message when time…
Browse files Browse the repository at this point in the history
… parse goes wrong
  • Loading branch information
Andrea Schiavini authored and plusjade committed Mar 1, 2012
1 parent 1a9411a commit 9c1cf75
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Rakefile
Expand Up @@ -46,7 +46,12 @@ task :post do
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
title = ENV["title"] || "new-post"
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
date = (Time.parse(ENV['date']) || Time.now).strftime('%Y-%m-%d')
begin
date = (Time.parse(ENV['date']) || Time.now).strftime('%Y-%m-%d')
rescue Exception => e
puts "Error - date format must be YYYY-MM-DD, please check you typed it correctly!"
exit -1
end
filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}")
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
Expand Down

0 comments on commit 9c1cf75

Please sign in to comment.