Commit bc59fd046f9f786c8bbc5512a9177359b384b329
1 parent
48a5012b
Exists in
master
and in
4 other branches
Add a warning prompt to the setup task
Showing
2 changed files
with
46 additions
and
5 deletions
Show diff stats
lib/tasks/gitlab/setup.rake
| 1 | 1 | namespace :gitlab do |
| 2 | 2 | namespace :app do |
| 3 | 3 | desc "GITLAB | Setup production application" |
| 4 | - task :setup => [ | |
| 5 | - 'db:setup', | |
| 6 | - 'db:seed_fu', | |
| 7 | - 'gitlab:enable_automerge' | |
| 8 | - ] | |
| 4 | + task :setup => :environment do | |
| 5 | + setup | |
| 6 | + end | |
| 7 | + | |
| 8 | + def setup | |
| 9 | + warn_user_is_not_gitlab | |
| 10 | + | |
| 11 | + puts "This will create the necessary database tables and seed the database." | |
| 12 | + puts "You will lose any previous data stored in the database." | |
| 13 | + ask_to_continue | |
| 14 | + puts "" | |
| 15 | + | |
| 16 | + Rake::Task["db:setup"].invoke | |
| 17 | + Rake::Task["db:seed_fu"].invoke | |
| 18 | + Rake::Task["gitlab:enable_automerge"].invoke | |
| 19 | + rescue Gitlab::TaskAbortedByUserError | |
| 20 | + puts "Quitting...".red | |
| 21 | + exit 1 | |
| 22 | + end | |
| 9 | 23 | end |
| 10 | 24 | end | ... | ... |
lib/tasks/gitlab/task_helpers.rake
| 1 | +module Gitlab | |
| 2 | + class TaskAbortedByUserError < StandardError; end | |
| 3 | +end | |
| 4 | + | |
| 1 | 5 | namespace :gitlab do |
| 2 | 6 | |
| 7 | + # Ask if the user wants to continue | |
| 8 | + # | |
| 9 | + # Returns "yes" the user chose to continue | |
| 10 | + # Raises Gitlab::TaskAbortedByUserError if the user chose *not* to continue | |
| 11 | + def ask_to_continue | |
| 12 | + answer = prompt("Do you want to continue (yes/no)? ".blue, %w{yes no}) | |
| 13 | + raise Gitlab::TaskAbortedByUserError unless answer == "yes" | |
| 14 | + end | |
| 15 | + | |
| 3 | 16 | # Check which OS is running |
| 4 | 17 | # |
| 5 | 18 | # It will primarily use lsb_relase to determine the OS. |
| ... | ... | @@ -22,6 +35,20 @@ namespace :gitlab do |
| 22 | 35 | os_name.try(:squish!) |
| 23 | 36 | end |
| 24 | 37 | |
| 38 | + # Prompt the user to input something | |
| 39 | + # | |
| 40 | + # message - the message to display before input | |
| 41 | + # choices - array of strings of acceptible answers or nil for any answer | |
| 42 | + # | |
| 43 | + # Returns the user's answer | |
| 44 | + def prompt(message, choices = nil) | |
| 45 | + begin | |
| 46 | + print(message) | |
| 47 | + answer = STDIN.gets.chomp | |
| 48 | + end while choices.present? && !choices.include?(answer) | |
| 49 | + answer | |
| 50 | + end | |
| 51 | + | |
| 25 | 52 | # Runs the given command and matches the output agains the given pattern |
| 26 | 53 | # |
| 27 | 54 | # Returns nil if nothing matched | ... | ... |