Skip to content

Commit c462eae

Browse files
committed
cli/command/container: minor cleanups: use Println
- use Println to print newline instead of custom format - suppress some errors to make my IDE and linters happier Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 8650ffe commit c462eae

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

cli/command/container/cp.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,12 @@ func NewCopyCommand(dockerCli command.Cli) *cobra.Command {
129129
Use: `cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
130130
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH`,
131131
Short: "Copy files/folders between a container and the local filesystem",
132-
Long: strings.Join([]string{
133-
"Copy files/folders between a container and the local filesystem\n",
134-
"\nUse '-' as the source to read a tar archive from stdin\n",
135-
"and extract it to a directory destination in a container.\n",
136-
"Use '-' as the destination to stream a tar archive of a\n",
137-
"container source to stdout.",
138-
}, ""),
132+
Long: `Copy files/folders between a container and the local filesystem
133+
134+
Use '-' as the source to read a tar archive from stdin
135+
and extract it to a directory destination in a container.
136+
Use '-' as the destination to stream a tar archive of a
137+
container source to stdout.`,
139138
Args: cli.ExactArgs(2),
140139
RunE: func(cmd *cobra.Command, args []string) error {
141140
if args[0] == "" {

cli/command/container/create.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
274274
if errdefs.IsNotFound(err) && namedRef != nil && options.pull == PullImageMissing {
275275
if !options.quiet {
276276
// we don't want to write to stdout anything apart from container.ID
277-
fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
277+
_, _ = fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
278278
}
279279

280280
if err := pullAndTagImage(); err != nil {
@@ -292,15 +292,15 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
292292
}
293293

294294
for _, w := range response.Warnings {
295-
_, _ = fmt.Fprintf(dockerCli.Err(), "WARNING: %s\n", w)
295+
_, _ = fmt.Fprintln(dockerCli.Err(), "WARNING:", w)
296296
}
297297
err = containerIDFile.Write(response.ID)
298298
return response.ID, err
299299
}
300300

301301
func warnOnOomKillDisable(hostConfig container.HostConfig, stderr io.Writer) {
302302
if hostConfig.OomKillDisable != nil && *hostConfig.OomKillDisable && hostConfig.Memory == 0 {
303-
fmt.Fprintln(stderr, "WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.")
303+
_, _ = fmt.Fprintln(stderr, "WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.")
304304
}
305305
}
306306

@@ -309,7 +309,7 @@ func warnOnOomKillDisable(hostConfig container.HostConfig, stderr io.Writer) {
309309
func warnOnLocalhostDNS(hostConfig container.HostConfig, stderr io.Writer) {
310310
for _, dnsIP := range hostConfig.DNS {
311311
if isLocalhost(dnsIP) {
312-
fmt.Fprintf(stderr, "WARNING: Localhost DNS setting (--dns=%s) may fail in containers.\n", dnsIP)
312+
_, _ = fmt.Fprintf(stderr, "WARNING: Localhost DNS setting (--dns=%s) may fail in containers.\n", dnsIP)
313313
return
314314
}
315315
}

cli/command/container/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
299299
for _, line := range strings.Split(statsTextBuffer.String(), "\n") {
300300
// In case the new text is shorter than the one we are writing over,
301301
// we'll append the "erase line" escape sequence to clear the remaining text.
302-
_, _ = fmt.Fprint(&statsTextBuffer, line, "\033[K\n")
302+
_, _ = fmt.Fprintln(&statsTextBuffer, line, "\033[K")
303303
}
304304

305305
// We might have fewer containers than before, so let's clear the remaining text

0 commit comments

Comments
 (0)