|
|
@@ -27,7 +27,6 @@ import (
|
|
|
|
|
|
"github.com/docker/compose-cli/api/containers"
|
|
|
"github.com/docker/compose-cli/formatter"
|
|
|
- "github.com/docker/compose-cli/utils"
|
|
|
)
|
|
|
|
|
|
// Opts contain run command options
|
|
|
@@ -93,15 +92,22 @@ func (r *Opts) ToContainerConfig(image string) (containers.ContainerConfig, erro
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
+var restartPolicyMap = map[string]string{
|
|
|
+ "": containers.RestartPolicyNone,
|
|
|
+ containers.RestartPolicyNone: containers.RestartPolicyNone,
|
|
|
+ containers.RestartPolicyAny: containers.RestartPolicyAny,
|
|
|
+ containers.RestartPolicyOnFailure: containers.RestartPolicyOnFailure,
|
|
|
+
|
|
|
+ containers.RestartPolicyRunNo: containers.RestartPolicyNone,
|
|
|
+ containers.RestartPolicyRunAlways: containers.RestartPolicyAny,
|
|
|
+}
|
|
|
+
|
|
|
func toRestartPolicy(value string) (string, error) {
|
|
|
- if value == "" {
|
|
|
- return containers.RestartPolicyNone, nil
|
|
|
+ value, ok := restartPolicyMap[value]
|
|
|
+ if !ok {
|
|
|
+ return "", fmt.Errorf("invalid restart value, must be one of %s", strings.Join(containers.RestartPolicyList, ", "))
|
|
|
}
|
|
|
- if utils.StringContains(containers.RestartPolicyList, value) {
|
|
|
- return value, nil
|
|
|
- }
|
|
|
-
|
|
|
- return "", fmt.Errorf("invalid restart value, must be one of %s", strings.Join(containers.RestartPolicyList, ", "))
|
|
|
+ return value, nil
|
|
|
}
|
|
|
|
|
|
func (r *Opts) toPorts() ([]containers.Port, error) {
|