From 9f86a9712d5dcaefb9acf33f829d0aa8f1295f54 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 24 Jun 2016 15:03:26 -0400 Subject: [PATCH] Merge service command and args as a string. Signed-off-by: Daniel Nephin (cherry picked from commit 674d227445887ea2f9a0fde6ebb7838bcce58578) Signed-off-by: Tibor Vass --- api/client/service/update.go | 27 +++++++++++++++------------ api/client/service/update_test.go | 3 +-- hack/vendor.sh | 1 + 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/api/client/service/update.go b/api/client/service/update.go index f3810cbae6..6aa7c10e73 100644 --- a/api/client/service/update.go +++ b/api/client/service/update.go @@ -13,6 +13,7 @@ import ( "github.com/docker/engine-api/types" "github.com/docker/engine-api/types/swarm" "github.com/docker/go-connections/nat" + shlex "github.com/flynn-archive/go-shlex" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -31,7 +32,7 @@ func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command { flags := cmd.Flags() flags.String("image", "", "Service image tag") - flags.StringSlice("arg", []string{}, "Service command args") + flags.String("args", "", "Service command args") addServiceFlags(cmd, opts) return cmd } @@ -91,12 +92,6 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error { } } - updateSlice := func(flag string, field *[]string) { - if flags.Changed(flag) { - *field, _ = flags.GetStringSlice(flag) - } - } - updateInt64Value := func(flag string, field *int64) { if flags.Changed(flag) { *field = flags.Lookup(flag).Value.(int64Value).Value() @@ -140,7 +135,7 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error { updateString(flagName, &spec.Name) updateLabels(flags, &spec.Labels) updateString("image", &cspec.Image) - updateSlice("arg", &cspec.Args) + updateStringToSlice(flags, "args", &cspec.Args) updateListOpts("env", &cspec.Env) updateString("workdir", &cspec.Dir) updateString(flagUser, &cspec.User) @@ -174,10 +169,7 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error { updateDurationOpt((flagRestartWindow), task.RestartPolicy.Window) } - if flags.Changed(flagConstraint) { - task.Placement = &swarm.Placement{} - updateSlice(flagConstraint, &task.Placement.Constraints) - } + // TODO: The constraints field is fixed in #23773 if err := updateReplicas(flags, &spec.Mode); err != nil { return err @@ -206,6 +198,17 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error { return nil } +func updateStringToSlice(flags *pflag.FlagSet, flag string, field *[]string) error { + if !flags.Changed(flag) { + return nil + } + + value, _ := flags.GetString(flag) + valueSlice, err := shlex.Split(value) + *field = valueSlice + return err +} + func updateLabels(flags *pflag.FlagSet, field *map[string]string) { if !flags.Changed(flagLabel) { return diff --git a/api/client/service/update_test.go b/api/client/service/update_test.go index 8238e3b7de..130e8b3e23 100644 --- a/api/client/service/update_test.go +++ b/api/client/service/update_test.go @@ -9,8 +9,7 @@ import ( func TestUpdateServiceArgs(t *testing.T) { flags := newUpdateCommand(nil).Flags() - flags.Set("arg", "the") - flags.Set("arg", "new args") + flags.Set("args", "the \"new args\"") spec := &swarm.ServiceSpec{} cspec := &spec.TaskTemplate.ContainerSpec diff --git a/hack/vendor.sh b/hack/vendor.sh index 6a3ec87259..4a90f2f910 100755 --- a/hack/vendor.sh +++ b/hack/vendor.sh @@ -164,5 +164,6 @@ clone git github.com/pkg/errors 01fa4104b9c248c8945d14d9f128454d5b28d595 clone git github.com/spf13/cobra 75205f23b3ea70dc7ae5e900d074e010c23c37e9 https://github.com/dnephin/cobra.git clone git github.com/spf13/pflag cb88ea77998c3f024757528e3305022ab50b43be clone git github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 +clone git github.com/flynn-archive/go-shlex 3f9db97f856818214da2e1057f8ad84803971cff clean