@@ -1091,6 +1091,39 @@ func replaceVersions(oldManifest, newManifest *types.VersionManifest, filename s
1091
1091
return ioutil .WriteFile (filename , []byte (s ), 0755 )
1092
1092
}
1093
1093
1094
+ // initTabwriter takes the stackManger, the format of the Header row and a variadic arguement
1095
+ // of strings (Headers) that is expected to comply with the Header format. It returns a Writer with sane defaults
1096
+ // to write the body row.
1097
+ func initTabwriter (s * StackManager , formatHeader string , headers ... interface {}) * tabwriter.Writer {
1098
+ w := new (tabwriter.Writer )
1099
+ w .Init (os .Stdout , 8 , 8 , 8 , ' ' , 0 )
1100
+ s .once .Do (func () {
1101
+ fmt .Fprintf (w , formatHeader , headers ... )
1102
+ })
1103
+ return w
1104
+ }
1105
+ // PrintStacksInfo prints to os.Stdout information about the stack.
1106
+ func (s * StackManager ) PrintStacksInfo () error {
1107
+ formatHeader := "%-15s %-22s %-10s %-20s %-25s\n "
1108
+ formatBody := " %-18s %-18s %-7s %-14s %-20s\n "
1109
+
1110
+ w := initTabwriter (s , formatHeader , "STACK-NAME" , "BLOCKCHAIN-PROVIDER" , "MEMBERS" , "STATUS" , "DOCKER COMPOSE DIR" )
1111
+
1112
+ status , err := isRunning (s )
1113
+ if err != nil {
1114
+ return err
1115
+ }
1116
+
1117
+ if status {
1118
+ fmt .Fprintf (w , formatBody , s .Stack .Name , s .Stack .BlockchainProvider , fmt .Sprint (len (s .Stack .Members )), "running" , filepath .Join (s .Stack .StackDir , "docker-compose.yml" ))
1119
+ } else {
1120
+ fmt .Fprintf (w , formatBody , s .Stack .Name , s .Stack .BlockchainProvider , fmt .Sprint (len (s .Stack .Members )), "not_running" , filepath .Join (s .Stack .StackDir , "docker-compose.yml" ))
1121
+ }
1122
+ fmt .Fprintln (w )
1123
+ w .Flush ()
1124
+
1125
+ return nil
1126
+ }
1094
1127
func (s * StackManager ) PrintStackInfo () error {
1095
1128
fmt .Print ("\n " )
1096
1129
if err := s .runDockerComposeCommand ("images" ); err != nil {
@@ -1106,31 +1139,40 @@ func (s *StackManager) PrintStackInfo() error {
1106
1139
1107
1140
// IsRunning prints to the stdout, the stack name and it status as "running" or "not_running".
1108
1141
func (s * StackManager ) IsRunning () error {
1109
- output , err := docker .RunDockerComposeCommandReturnsStdout (s .Stack .StackDir , "ps" )
1142
+ formatHeader := " %-15s %-20s\n "
1143
+ formatBody := " %-13s %-20s"
1144
+
1145
+ w := initTabwriter (s , formatHeader , "STACK-NAME" , "STATUS" )
1146
+
1147
+ status , err := isRunning (s )
1110
1148
if err != nil {
1111
1149
return err
1112
1150
}
1113
1151
1114
- formatHeader := "\n %s\t %s\t "
1115
- formatBody := "\n %s\t %s\t "
1116
-
1117
- w := new (tabwriter.Writer )
1118
- w .Init (os .Stdout , 8 , 8 , 8 , '\t' , 0 )
1119
-
1120
- s .once .Do (func () {
1121
- fmt .Fprintf (w , formatHeader , "STACK" , "STATUS" )
1122
- })
1123
-
1124
- if strings .Contains (string (output ), s .Stack .Name ) { // if the output contains the stack name, it means the container is running.
1152
+ if status {
1125
1153
fmt .Fprintf (w , formatBody , s .Stack .Name , "running" )
1126
1154
} else {
1127
1155
fmt .Fprintf (w , formatBody , s .Stack .Name , "not_running" )
1128
1156
}
1129
1157
fmt .Fprintln (w )
1130
1158
w .Flush ()
1159
+
1131
1160
return nil
1132
1161
}
1133
1162
1163
+ // isRunning returns true if a stack on the local machine is currently running, otherwise false.
1164
+ func isRunning (s * StackManager ) (bool , error ) {
1165
+ output , err := docker .RunDockerComposeCommandReturnsStdout (s .Stack .StackDir , "ps" )
1166
+ if err != nil {
1167
+ return false , err
1168
+ }
1169
+ if strings .Contains (string (output ), s .Stack .Name ) { // from running `docker compose ps`, if the output contains the stack name, it means the container is running.
1170
+ return true , nil
1171
+ }
1172
+
1173
+ return false , nil
1174
+ }
1175
+
1134
1176
func (s * StackManager ) disableFireflyCoreContainers () error {
1135
1177
compose := s .buildDockerCompose ()
1136
1178
for _ , member := range s .Stack .Members {
0 commit comments