Browse code

install: Adds confirmation before overwriting existing source_dir

fhemberger authored on 04/09/2011 at 12:25:04
Showing 1 changed files
... ...
@@ -27,6 +27,9 @@ server_port     = "4000"      # port for preview server eg. localhost:4000
27 27
 
28 28
 desc "Initial setup for Octopress: copies the default theme into the path of Jekyll's generator. Rake install defaults to rake install[classic] to install a different theme run rake install[some_theme_name]"
29 29
 task :install, :theme do |t, args|
30
+  if File.directory?(source_dir) || File.directory?("sass")
31
+    abort("rake aborted!") if ask("A theme is already installed, proceeding will overwrite existing files. Are you sure?", ['y', 'n']) == 'n'
32
+  end
30 33
   # copy theme into working Jekyll directories
31 34
   theme = args.theme || 'classic'
32 35
   puts "## Copying "+theme+" theme into ./#{source_dir} and ./sass"
... ...
@@ -293,6 +296,20 @@ def ok_failed(condition)
293 293
   end
294 294
 end
295 295
 
296
+def get_stdin(message)
297
+  print message
298
+  STDIN.gets.chomp
299
+end
300
+
301
+def ask(message, valid_options)
302
+  if valid_options
303
+    answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
304
+  else
305
+    answer = get_stdin(message)
306
+  end
307
+  answer
308
+end
309
+
296 310
 desc "list tasks"
297 311
 task :list do
298 312
   puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}"