-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoolbelt.functions
84 lines (69 loc) · 2.32 KB
/
toolbelt.functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# This file is part of shellfire heroku. It is subject to the licence terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/heroku/master/COPYRIGHT. No part of shellfire heroku, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
# Copyright © 2015 The developers of shellfire heroku. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/heroku/master/COPYRIGHT.
heroku_toolbelt_initialise()
{
local TMP_FILE
core_temporaryFiles_newFileToRemoveOnExit
_heroku_toolbelt_standardOutputFilePath="$TMP_FILE"
core_temporaryFiles_newFileToRemoveOnExit
_heroku_toolbelt_standardErrorFilePath="$TMP_FILE"
}
core_dependency_requires '*' heroku
heroku_toolbelt_inRepository()
{
local exitOnError="$1"
local printStandardOut="$2"
shift 2
pushd "$heroku_repositoryPath"
set +e
heroku "$@" 1>"$_heroku_toolbelt_standardOutputFilePath" 2>"$_heroku_toolbelt_standardErrorFilePath"
local exitCode=$?
set -e
popd
local warningLevel
if [ $exitCode -ne 0 ]; then
warningLevel=WARN
else
warningLevel=INFO
fi
if $printStandardOut; then
_heroku_toolbelt_inRepository_printLinesIfAny "$warningLevel" 'stdout' "$_heroku_toolbelt_standardOutputFilePath"
fi
_heroku_toolbelt_inRepository_printLinesIfAny "$warningLevel" 'stderr' "$_heroku_toolbelt_standardErrorFilePath"
if [ $exitCode -ne 0 ]; then
if $exitOnError; then
core_exitError $core_commandLine_exitCode_SOFTWARE "heroku '$@' failed with exit code '$exitCode'"
fi
fi
}
_heroku_toolbelt_inRepository_printLine()
{
local message
if $afterFirst; then
message="> $line"
else
message="$line"
fi
core_message "$warningLevel" "heroku: $fileDescriptor: $message"
}
_heroku_toolbelt_inRepository_printLinesIfAny()
{
local warningLevel="$1"
local fileDescriptor="$2"
local linesFilePath="$3"
if [ ! -s "$linesFilePath" ]; then
return 0
fi
local afterFirst=false
local line
while IFS= read -r line
do
_heroku_toolbelt_inRepository_printLine
afterFirst=true
done <"$linesFilePath"
# Read any final line not terminated by '\n'; too bad
if [ -n line ]; then
_heroku_toolbelt_inRepository_printLine
afterFirst=true
fi
}