Merge service command and args as a string.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
(cherry picked from commit 674d227445
)
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
d8e9dbf628
commit
9f86a9712d
3 changed files with 17 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue