Skip to content

Commit

Permalink
disable label printing by default
Browse files Browse the repository at this point in the history
  • Loading branch information
turtletowerz committed Dec 18, 2024
1 parent 4836b53 commit 83bdf97
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/urfave/cli/v2"
)

func parseFromJSON(cli *client.Client, ct *types.ContainerJSON) ([]string, error) {
func parseFromJSON(cli *client.Client, ct *types.ContainerJSON, labels bool) ([]string, error) {
imgdata, _, err := cli.ImageInspectWithRaw(context.Background(), ct.Image)
if err != nil {
return nil, errors.Wrap(err, "getting container image")
Expand Down Expand Up @@ -47,7 +47,6 @@ func parseFromJSON(cli *client.Client, ct *types.ContainerJSON) ([]string, error
opt[string]{ct.Config.WorkingDir, imgdata.Config.WorkingDir, "--workdir="},
opt[string]{ct.HostConfig.LogConfig.Type, "json-file", "--log-driver="},
optMap{ct.HostConfig.LogConfig.Config, "--log-opt "},
optFunc[twoOf[map[string]string]]{twoOf[map[string]string]{ct.Config.Labels, imgdata.Config.Labels, "--label="}, handleLabels},
optFunc[twoOf[[]string]]{twoOf[[]string]{ct.HostConfig.CapAdd, ct.HostConfig.CapDrop, ""}, handleCapabilities},
opt[bool]{ct.HostConfig.ReadonlyRootfs, false, "--read-only"},
optSlice[string]{ct.HostConfig.SecurityOpt, nil, "--security-opt="},
Expand Down Expand Up @@ -138,6 +137,10 @@ func parseFromJSON(cli *client.Client, ct *types.ContainerJSON) ([]string, error
optMap{ct.HostConfig.Annotations, "--annotation "},
}

if labels {
options = append(options, optFunc[twoOf[map[string]string]]{twoOf[map[string]string]{ct.Config.Labels, imgdata.Config.Labels, "--label="}, handleLabels})
}

for _, v := range options {
if vals := v.Values(); v != nil {
flags = append(flags, vals...)
Expand Down Expand Up @@ -176,15 +179,15 @@ func _main(ctx *cli.Context) error {
return errors.New("only 1 container can be inspected at a time")
}

flags, err = parseFromJSON(ctcli, &data[0])
flags, err = parseFromJSON(ctcli, &data[0], ctx.Bool("labels"))
} else {
name := ctx.Args().First()
ct, err := ctcli.ContainerInspect(context.Background(), name)
if err != nil {
return errors.Wrapf(err, "getting container with name %q", name)
}

flags, err = parseFromJSON(ctcli, &ct)
flags, err = parseFromJSON(ctcli, &ct, ctx.Bool("labels"))
}

if err != nil {
Expand Down Expand Up @@ -231,6 +234,10 @@ func main() {
Aliases: []string{"s"},
Usage: "Accept input from STDIN",
},
&cli.BoolFlag{
Name: "labels",
Usage: "Include labels as container information",
},
},
}

Expand Down

0 comments on commit 83bdf97

Please sign in to comment.