Skip to content

Commit 4808d1b

Browse files
authored
Merge pull request #5783 from thaJeztah/newline_galore
assorted cleanups: use Println, rename vars for consistency
2 parents 4d7fe01 + 987da09 commit 4808d1b

71 files changed

Lines changed: 382 additions & 367 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cli-plugins/examples/helloworld/main.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ import (
1212
)
1313

1414
func main() {
15-
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
15+
plugin.Run(func(dockerCLI command.Cli) *cobra.Command {
1616
goodbye := &cobra.Command{
1717
Use: "goodbye",
1818
Short: "Say Goodbye instead of Hello",
1919
Run: func(cmd *cobra.Command, _ []string) {
20-
fmt.Fprintln(dockerCli.Out(), "Goodbye World!")
20+
_, _ = fmt.Fprintln(dockerCLI.Out(), "Goodbye World!")
2121
},
2222
}
2323
apiversion := &cobra.Command{
2424
Use: "apiversion",
2525
Short: "Print the API version of the server",
2626
RunE: func(_ *cobra.Command, _ []string) error {
27-
cli := dockerCli.Client()
28-
ping, err := cli.Ping(context.Background())
27+
apiClient := dockerCLI.Client()
28+
ping, err := apiClient.Ping(context.Background())
2929
if err != nil {
3030
return err
3131
}
32-
fmt.Println(ping.APIVersion)
32+
_, _ = fmt.Println(ping.APIVersion)
3333
return nil
3434
},
3535
}
@@ -38,7 +38,7 @@ func main() {
3838
Use: "exitstatus2",
3939
Short: "Exit with status 2",
4040
RunE: func(_ *cobra.Command, _ []string) error {
41-
fmt.Fprintln(dockerCli.Err(), "Exiting with error status 2")
41+
_, _ = fmt.Fprintln(dockerCLI.Err(), "Exiting with error status 2")
4242
os.Exit(2)
4343
return nil
4444
},
@@ -56,33 +56,33 @@ func main() {
5656
return err
5757
}
5858
if preRun {
59-
fmt.Fprintf(dockerCli.Err(), "Plugin PersistentPreRunE called")
59+
_, _ = fmt.Fprintln(dockerCLI.Err(), "Plugin PersistentPreRunE called")
6060
}
6161
return nil
6262
},
6363
RunE: func(cmd *cobra.Command, args []string) error {
6464
if debug {
65-
fmt.Fprintf(dockerCli.Err(), "Plugin debug mode enabled")
65+
_, _ = fmt.Fprintln(dockerCLI.Err(), "Plugin debug mode enabled")
6666
}
6767

6868
switch optContext {
6969
case "Christmas":
70-
fmt.Fprintf(dockerCli.Out(), "Merry Christmas!\n")
70+
_, _ = fmt.Fprintln(dockerCLI.Out(), "Merry Christmas!")
7171
return nil
7272
case "":
7373
// nothing
7474
}
7575

7676
if who == "" {
77-
who, _ = dockerCli.ConfigFile().PluginConfig("helloworld", "who")
77+
who, _ = dockerCLI.ConfigFile().PluginConfig("helloworld", "who")
7878
}
7979
if who == "" {
8080
who = "World"
8181
}
8282

83-
fmt.Fprintf(dockerCli.Out(), "Hello %s!\n", who)
84-
dockerCli.ConfigFile().SetPluginConfig("helloworld", "lastwho", who)
85-
return dockerCli.ConfigFile().Save()
83+
_, _ = fmt.Fprintln(dockerCLI.Out(), "Hello", who)
84+
dockerCLI.ConfigFile().SetPluginConfig("helloworld", "lastwho", who)
85+
return dockerCLI.ConfigFile().Save()
8686
},
8787
}
8888

cli-plugins/hooks/printer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func PrintNextSteps(out io.Writer, messages []string) {
1111
if len(messages) == 0 {
1212
return
1313
}
14-
fmt.Fprintln(out, aec.Bold.Apply("\nWhat's next:"))
14+
_, _ = fmt.Fprintln(out, aec.Bold.Apply("\nWhat's next:"))
1515
for _, n := range messages {
16-
_, _ = fmt.Fprintf(out, " %s\n", n)
16+
_, _ = fmt.Fprintln(out, " ", n)
1717
}
1818
}

cli/command/checkpoint/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
4040
return cmd
4141
}
4242

43-
func runCreate(ctx context.Context, dockerCli command.Cli, opts createOptions) error {
44-
err := dockerCli.Client().CheckpointCreate(ctx, opts.container, checkpoint.CreateOptions{
43+
func runCreate(ctx context.Context, dockerCLI command.Cli, opts createOptions) error {
44+
err := dockerCLI.Client().CheckpointCreate(ctx, opts.container, checkpoint.CreateOptions{
4545
CheckpointID: opts.checkpoint,
4646
CheckpointDir: opts.checkpointDir,
4747
Exit: !opts.leaveRunning,
@@ -50,6 +50,6 @@ func runCreate(ctx context.Context, dockerCli command.Cli, opts createOptions) e
5050
return err
5151
}
5252

53-
fmt.Fprintf(dockerCli.Out(), "%s\n", opts.checkpoint)
53+
_, _ = fmt.Fprintln(dockerCLI.Out(), opts.checkpoint)
5454
return nil
5555
}

cli/command/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (cli *DockerCli) CurrentVersion() string {
114114
// Client returns the APIClient
115115
func (cli *DockerCli) Client() client.APIClient {
116116
if err := cli.initialize(); err != nil {
117-
_, _ = fmt.Fprintf(cli.Err(), "Failed to initialize: %s\n", err)
117+
_, _ = fmt.Fprintln(cli.Err(), "Failed to initialize:", err)
118118
os.Exit(1)
119119
}
120120
return cli.client
@@ -475,7 +475,7 @@ func (cli *DockerCli) DockerEndpoint() docker.Endpoint {
475475
if err := cli.initialize(); err != nil {
476476
// Note that we're not terminating here, as this function may be used
477477
// in cases where we're able to continue.
478-
_, _ = fmt.Fprintf(cli.Err(), "%v\n", cli.initErr)
478+
_, _ = fmt.Fprintln(cli.Err(), cli.initErr)
479479
}
480480
return cli.dockerEndpoint
481481
}

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

cli/command/context/create.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func longCreateDescription() string {
3434
buf := bytes.NewBuffer(nil)
3535
buf.WriteString("Create a context\n\nDocker endpoint config:\n\n")
3636
tw := tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
37-
fmt.Fprintln(tw, "NAME\tDESCRIPTION")
37+
_, _ = fmt.Fprintln(tw, "NAME\tDESCRIPTION")
3838
for _, d := range dockerConfigKeysDescriptions {
39-
fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
39+
_, _ = fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
4040
}
41-
tw.Flush()
41+
_ = tw.Flush()
4242
buf.WriteString("\nExample:\n\n$ docker context create my-context --description \"some description\" --docker \"host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file\"\n")
4343
return buf.String()
4444
}
@@ -79,8 +79,8 @@ func RunCreate(dockerCLI command.Cli, o *CreateOptions) error {
7979
err = createNewContext(s, o)
8080
}
8181
if err == nil {
82-
fmt.Fprintln(dockerCLI.Out(), o.Name)
83-
fmt.Fprintf(dockerCLI.Err(), "Successfully created context %q\n", o.Name)
82+
_, _ = fmt.Fprintln(dockerCLI.Out(), o.Name)
83+
_, _ = fmt.Fprintf(dockerCLI.Err(), "Successfully created context %q\n", o.Name)
8484
}
8585
return err
8686
}

cli/command/context/import.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func RunImport(dockerCli command.Cli, name string, source string) error {
4545
return err
4646
}
4747

48-
fmt.Fprintln(dockerCli.Out(), name)
49-
fmt.Fprintf(dockerCli.Err(), "Successfully imported context %q\n", name)
48+
_, _ = fmt.Fprintln(dockerCli.Out(), name)
49+
_, _ = fmt.Fprintf(dockerCli.Err(), "Successfully imported context %q\n", name)
5050
return nil
5151
}

cli/command/context/update.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ func longUpdateDescription() string {
2424
buf := bytes.NewBuffer(nil)
2525
buf.WriteString("Update a context\n\nDocker endpoint config:\n\n")
2626
tw := tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
27-
fmt.Fprintln(tw, "NAME\tDESCRIPTION")
27+
_, _ = fmt.Fprintln(tw, "NAME\tDESCRIPTION")
2828
for _, d := range dockerConfigKeysDescriptions {
29-
fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
29+
_, _ = fmt.Fprintf(tw, "%s\t%s\n", d.name, d.description)
3030
}
31-
tw.Flush()
31+
_ = tw.Flush()
3232
buf.WriteString("\nExample:\n\n$ docker context update my-context --description \"some description\" --docker \"host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file\"\n")
3333
return buf.String()
3434
}
@@ -93,8 +93,8 @@ func RunUpdate(dockerCLI command.Cli, o *UpdateOptions) error {
9393
}
9494
}
9595

96-
fmt.Fprintln(dockerCLI.Out(), o.Name)
97-
fmt.Fprintf(dockerCLI.Err(), "Successfully updated context %q\n", o.Name)
96+
_, _ = fmt.Fprintln(dockerCLI.Out(), o.Name)
97+
_, _ = fmt.Fprintf(dockerCLI.Err(), "Successfully updated context %q\n", o.Name)
9898
return nil
9999
}
100100

0 commit comments

Comments
 (0)