Skip to content

Commit 2f44bc0

Browse files
authored
Merge pull request #216 from Random-Liu/add-no-trunc
Add no-trunc for `crictl images` and `crictl sandboxes`.
2 parents 23a53d2 + 95044a5 commit 2f44bc0

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

cmd/crictl/image.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ var listImageCommand = cli.Command{
105105
Name: "digests",
106106
Usage: "Show digests",
107107
},
108+
cli.BoolFlag{
109+
Name: "no-trunc",
110+
Usage: "Show output without truncating the ID",
111+
},
108112
},
109113
Action: func(context *cli.Context) error {
110114
if err := getImageClient(context); err != nil {
@@ -129,6 +133,7 @@ var listImageCommand = cli.Command{
129133
verbose := context.Bool("verbose")
130134
showDigest := context.Bool("digests")
131135
quiet := context.Bool("quiet")
136+
noTrunc := context.Bool("no-trunc")
132137
if !verbose && !quiet {
133138
if showDigest {
134139
fmt.Fprintln(w, "IMAGE\tTAG\tDIGEST\tIMAGE ID\tSIZE")
@@ -141,17 +146,19 @@ var listImageCommand = cli.Command{
141146
fmt.Printf("%s\n", image.Id)
142147
continue
143148
}
144-
145149
if !verbose {
146150
imageName, repoDigest := normalizeRepoDigest(image.RepoDigests)
147151
repoTagPairs := normalizeRepoTagPair(image.RepoTags, imageName)
148152
size := units.HumanSizeWithPrecision(float64(image.GetSize_()), 3)
149-
trunctedImage := strings.TrimPrefix(image.Id, "sha256:")[:truncatedIDLen]
153+
id := image.Id
154+
if !noTrunc {
155+
id = strings.TrimPrefix(image.Id, "sha256:")[:truncatedIDLen]
156+
}
150157
for _, repoTagPair := range repoTagPairs {
151158
if showDigest {
152-
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", repoTagPair[0], repoTagPair[1], repoDigest, trunctedImage, size)
159+
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", repoTagPair[0], repoTagPair[1], repoDigest, id, size)
153160
} else {
154-
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", repoTagPair[0], repoTagPair[1], trunctedImage, size)
161+
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", repoTagPair[0], repoTagPair[1], id, size)
155162
}
156163
}
157164
continue

cmd/crictl/sandbox.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ var listPodSandboxCommand = cli.Command{
192192
Name: "output, o",
193193
Usage: "Output format, One of: json|yaml|table",
194194
},
195+
cli.BoolFlag{
196+
Name: "no-trunc",
197+
Usage: "Show output without truncating the ID",
198+
},
195199
},
196200
Action: func(context *cli.Context) error {
197201
var err error
@@ -205,6 +209,7 @@ var listPodSandboxCommand = cli.Command{
205209
verbose: context.Bool("verbose"),
206210
quiet: context.Bool("quiet"),
207211
output: context.String("output"),
212+
noTrunc: context.Bool("no-trunc"),
208213
}
209214
opts.labels, err = parseLabelStringSlice(context.StringSlice("label"))
210215
if err != nil {
@@ -417,9 +422,12 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error {
417422
if !opts.verbose {
418423
createdAt := time.Unix(0, pod.CreatedAt)
419424
ctm := units.HumanDuration(time.Now().UTC().Sub(createdAt)) + " ago"
420-
truncatedID := strings.TrimPrefix(pod.Id, "")[:truncatedIDLen]
425+
id := pod.Id
426+
if !opts.noTrunc {
427+
id = strings.TrimPrefix(pod.Id, "")[:truncatedIDLen]
428+
}
421429
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\n",
422-
truncatedID, ctm, pod.State, pod.Metadata.Name, pod.Metadata.Namespace, pod.Metadata.Attempt)
430+
id, ctm, pod.State, pod.Metadata.Name, pod.Metadata.Namespace, pod.Metadata.Attempt)
423431
continue
424432
}
425433

0 commit comments

Comments
 (0)