Fix test command to make it work as string / slice

see #8
This commit is contained in:
2022-04-01 16:58:13 +02:00
parent f99f146af2
commit f8dcd2026b
2 changed files with 38 additions and 12 deletions

View File

@@ -170,18 +170,18 @@ func parseCommand(s *Service) {
}
// following the command type, it can be a "slice" or a simple sting, so we need to check it
switch s.RawCommand.(type) {
switch v := s.RawCommand.(type) {
case string:
// use shlex to parse the command
command, err := shlex.Split(s.RawCommand.(string))
command, err := shlex.Split(v)
if err != nil {
log.Fatal(err)
}
s.Command = command
case []string:
s.Command = s.RawCommand.([]string)
s.Command = v
case []interface{}:
for _, v := range s.RawCommand.([]interface{}) {
for _, v := range v {
s.Command = append(s.Command, v.(string))
}
default:
@@ -196,11 +196,11 @@ func parseEnvFiles(s *Service) {
return
}
envfiles := make([]string, 0)
switch s.RawEnvFiles.(type) {
switch v := s.RawEnvFiles.(type) {
case []string:
envfiles = s.RawEnvFiles.([]string)
envfiles = v
case []interface{}:
for _, v := range s.RawEnvFiles.([]interface{}) {
for _, v := range v {
envfiles = append(envfiles, v.(string))
}
default:
@@ -209,3 +209,28 @@ func parseEnvFiles(s *Service) {
}
s.EnvFiles = envfiles
}
func parseHealthCheck(s *Service) {
// HealthCheck command can be a string or slice of strings
if s.HealthCheck.RawTest == nil {
return
}
switch v := s.HealthCheck.RawTest.(type) {
case string:
var err error
s.HealthCheck.Test, err = shlex.Split(v)
if err != nil {
log.Fatal(err)
}
case []string:
s.HealthCheck.Test = v
case []interface{}:
for _, v := range v {
s.HealthCheck.Test = append(s.HealthCheck.Test, v.(string))
}
default:
log.Printf("%+v %T", s.HealthCheck.RawTest, s.HealthCheck.RawTest)
log.Fatal("HealthCheck type not supported")
}
}