Extract task helper methods
This commit is contained in:
parent
9655350c79
commit
224da71177
3 changed files with 39 additions and 63 deletions
|
@ -908,29 +908,6 @@ namespace :gitlab do
|
||||||
puts ""
|
puts ""
|
||||||
end
|
end
|
||||||
|
|
||||||
# Runs the given command
|
|
||||||
#
|
|
||||||
# Returns nil if the command was not found
|
|
||||||
# Returns the output of the command otherwise
|
|
||||||
#
|
|
||||||
# see also #run_and_match
|
|
||||||
def run(command)
|
|
||||||
unless `#{command} 2>/dev/null`.blank?
|
|
||||||
`#{command}`
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Runs the given command and matches the output agains the given pattern
|
|
||||||
#
|
|
||||||
# Returns nil if nothing matched
|
|
||||||
# Retunrs the MatchData if the pattern matched
|
|
||||||
#
|
|
||||||
# see also #run
|
|
||||||
# see also String#match
|
|
||||||
def run_and_match(command, pattern)
|
|
||||||
run(command).try(:match, pattern)
|
|
||||||
end
|
|
||||||
|
|
||||||
def see_database_guide
|
def see_database_guide
|
||||||
"doc/install/databases.md"
|
"doc/install/databases.md"
|
||||||
end
|
end
|
||||||
|
@ -952,18 +929,4 @@ namespace :gitlab do
|
||||||
puts " #{step}"
|
puts " #{step}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def warn_user_is_not_gitlab
|
|
||||||
unless @warned_user_not_gitlab
|
|
||||||
current_user = run("whoami").chomp
|
|
||||||
unless current_user == "gitlab"
|
|
||||||
puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"
|
|
||||||
puts " You are running as user #{current_user.magenta}, we hope you know what you are doing."
|
|
||||||
puts " Some tests may pass\/fail for the wrong reason."
|
|
||||||
puts " For meaningful results you should run this as user #{"gitlab".magenta}."
|
|
||||||
puts ""
|
|
||||||
end
|
|
||||||
@warned_user_not_gitlab = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -80,31 +80,5 @@ namespace :gitlab do
|
||||||
puts "Git:\t\t#{Gitlab.config.git.bin_path}"
|
puts "Git:\t\t#{Gitlab.config.git.bin_path}"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Helper methods
|
|
||||||
|
|
||||||
# Runs the given command and matches the output agains the given pattern
|
|
||||||
#
|
|
||||||
# Returns nil if nothing matched
|
|
||||||
# Retunrs the MatchData if the pattern matched
|
|
||||||
#
|
|
||||||
# see also #run
|
|
||||||
# see also String#match
|
|
||||||
def run_and_match(command, regexp)
|
|
||||||
run(command).try(:match, regexp)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Runs the given command
|
|
||||||
#
|
|
||||||
# Returns nil if the command was not found
|
|
||||||
# Returns the output of the command otherwise
|
|
||||||
#
|
|
||||||
# see also #run_and_match
|
|
||||||
def run(command)
|
|
||||||
unless `#{command} 2>/dev/null`.blank?
|
|
||||||
`#{command}`
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
39
lib/tasks/gitlab/task_helpers.rake
Normal file
39
lib/tasks/gitlab/task_helpers.rake
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
namespace :gitlab do
|
||||||
|
|
||||||
|
# Runs the given command and matches the output agains the given pattern
|
||||||
|
#
|
||||||
|
# Returns nil if nothing matched
|
||||||
|
# Retunrs the MatchData if the pattern matched
|
||||||
|
#
|
||||||
|
# see also #run
|
||||||
|
# see also String#match
|
||||||
|
def run_and_match(command, regexp)
|
||||||
|
run(command).try(:match, regexp)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Runs the given command
|
||||||
|
#
|
||||||
|
# Returns nil if the command was not found
|
||||||
|
# Returns the output of the command otherwise
|
||||||
|
#
|
||||||
|
# see also #run_and_match
|
||||||
|
def run(command)
|
||||||
|
unless `#{command} 2>/dev/null`.blank?
|
||||||
|
`#{command}`
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def warn_user_is_not_gitlab
|
||||||
|
unless @warned_user_not_gitlab
|
||||||
|
current_user = run("whoami").chomp
|
||||||
|
unless current_user == "gitlab"
|
||||||
|
puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"
|
||||||
|
puts " You are running as user #{current_user.magenta}, we hope you know what you are doing."
|
||||||
|
puts " Things may work\/fail for the wrong reasons."
|
||||||
|
puts " For correct results you should run this as user #{"gitlab".magenta}."
|
||||||
|
puts ""
|
||||||
|
end
|
||||||
|
@warned_user_not_gitlab = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue