summaryrefslogtreecommitdiff
path: root/Rakefile
diff options
context:
space:
mode:
authorAndrea Schiavini <andrea.schiavini@gmail.com>2012-02-13 12:54:25 +0100
committerJade Dominguez <plusjade@gmail.com>2012-03-01 03:38:08 -0800
commit9c1cf75ce89f9c99504a1f812a0f88fffd0430a1 (patch)
tree684c69f4b5681e7d00cd288717eeda59140e5c1c /Rakefile
parent1a9411aea96ef71839de44890889dda751227e6a (diff)
Added exception handling to display a user friendly message when time parse goes wrong
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile7
1 files changed, 6 insertions, 1 deletions
diff --git a/Rakefile b/Rakefile
index 24319d1..b19d129 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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'