Do not truncate ID on docker service ps --quiet

Running `docker service ps --quiet` should print the
full, non-truncated ID, even if the `--no-trunc` option
is not set.

This patch disables truncation if the `--quiet` flag
is set.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2017-09-30 22:19:34 +02:00
parent 583015b896
commit c5f267d95c
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 23 additions and 0 deletions

View File

@ -14,6 +14,7 @@ type fakeClient struct {
serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
serviceListFunc func(context.Context, types.ServiceListOptions) ([]swarm.Service, error)
taskListFunc func(context.Context, types.TaskListOptions) ([]swarm.Task, error)
infoFunc func(ctx context.Context) (types.Info, error)
}
@ -22,6 +23,9 @@ func (f *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions
}
func (f *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
if f.taskListFunc != nil {
return f.taskListFunc(ctx, options)
}
return nil, nil
}

View File

@ -69,6 +69,9 @@ func runPS(dockerCli command.Cli, options psOptions) error {
if len(format) == 0 {
format = task.DefaultFormat(dockerCli.ConfigFile(), options.quiet)
}
if options.quiet {
options.noTrunc = true
}
if err := task.Print(ctx, dockerCli, tasks, idresolver.New(client, options.noResolve), !options.noTrunc, options.quiet, format); err != nil {
return err
}

View File

@ -90,6 +90,22 @@ func TestRunPSWarnsOnNotFound(t *testing.T) {
assert.EqualError(t, err, "no such service: bar")
}
func TestRunPSQuiet(t *testing.T) {
client := &fakeClient{
serviceListFunc: func(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
return []swarm.Service{{ID: "foo"}}, nil
},
taskListFunc: func(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
return []swarm.Task{{ID: "sxabyp0obqokwekpun4rjo0b3"}}, nil
},
}
cli := test.NewFakeCli(client)
err := runPS(cli, psOptions{services: []string{"foo"}, quiet: true, filter: opts.NewFilterOpt()})
require.NoError(t, err)
assert.Equal(t, "sxabyp0obqokwekpun4rjo0b3\n", cli.OutBuffer().String())
}
func TestUpdateNodeFilter(t *testing.T) {
selfNodeID := "foofoo"
filter := filters.NewArgs()