cmd/ctr, service/containers: implement container filter

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-06-21 15:29:58 -07:00
parent 3332042ab6
commit 396d89e423
16 changed files with 409 additions and 189 deletions

52
cmd/ctr/labels.go Normal file
View File

@@ -0,0 +1,52 @@
package main
import (
"errors"
"fmt"
"strings"
"github.com/urfave/cli"
)
var containersSetLabelsCommand = cli.Command{
Name: "set-labels",
Usage: "Set and clear labels for a container.",
ArgsUsage: "[flags] <name> [<key>=<value>, ...]",
Description: "Set and clear labels for a container.",
Flags: []cli.Flag{},
Action: func(clicontext *cli.Context) error {
var (
ctx, cancel = appContext(clicontext)
containerID, labels = objectWithLabelArgs(clicontext)
)
defer cancel()
client, err := newClient(clicontext)
if err != nil {
return err
}
if containerID == "" {
return errors.New("please specify a container")
}
container, err := client.LoadContainer(ctx, containerID)
if err != nil {
return err
}
setlabels, err := container.SetLabels(ctx, labels)
if err != nil {
return err
}
var labelStrings []string
for k, v := range setlabels {
labelStrings = append(labelStrings, fmt.Sprintf("%s=%s", k, v))
}
fmt.Println(strings.Join(labelStrings, ","))
return nil
},
}