/
format.go
44 lines (38 loc) · 1.48 KB
/
format.go
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
package main
import (
"github.com/ubclaunchpad/inertia/common"
)
const (
msgBuildInProgress = "It appears that your build is still in progress."
msgNoContainersActive = "No containers are active."
msgNoDeployment = "No deployment found - try running 'inertia [VPS] up'"
)
func formatStatus(s *common.DeploymentStatus) string {
inertiaStatus := "inertia daemon " + s.InertiaVersion + "\n"
branchStatus := " - Branch: " + s.Branch + "\n"
commitStatus := " - Commit: " + s.CommitHash + "\n"
commitMessage := " - Message: " + s.CommitMessage + "\n"
buildTypeStatus := " - Build Type: " + s.BuildType + "\n"
statusString := inertiaStatus + branchStatus + commitStatus + commitMessage + buildTypeStatus
// If no branch/commit, then it's likely the deployment has not
// been instantiated on the remote yet
if s.Branch == "" && s.CommitHash == "" && s.CommitMessage == "" {
return statusString + msgNoDeployment
}
// If build container is active, that means that a build
// attempt was made but only the daemon and docker-compose
// are active, indicating a build failure or build-in-progress
if len(s.Containers) == 0 {
errorString := statusString + msgNoContainersActive
if s.BuildContainerActive {
errorString = statusString + msgBuildInProgress
}
return errorString
}
activeContainers := "Active containers:\n"
for _, container := range s.Containers {
activeContainers += " - " + container + "\n"
}
statusString += activeContainers
return statusString
}