Skip to content

Commit 53aed61

Browse files
committed
cli/command/plugin: minor cleanups: use Println, rename vars
- use Println to print newline instead of custom format - use dockerCLI with Go's standard camelCase casing. - suppress some errors to make my IDE and linters happier Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 35e74d5 commit 53aed61

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

cli/command/plugin/install.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti
104104
return options, nil
105105
}
106106

107-
func runInstall(ctx context.Context, dockerCli command.Cli, opts pluginOptions) error {
107+
func runInstall(ctx context.Context, dockerCLI command.Cli, opts pluginOptions) error {
108108
var localName string
109109
if opts.localName != "" {
110110
aref, err := reference.ParseNormalizedNamed(opts.localName)
@@ -117,31 +117,31 @@ func runInstall(ctx context.Context, dockerCli command.Cli, opts pluginOptions)
117117
localName = reference.FamiliarString(reference.TagNameOnly(aref))
118118
}
119119

120-
options, err := buildPullConfig(ctx, dockerCli, opts, "plugin install")
120+
options, err := buildPullConfig(ctx, dockerCLI, opts, "plugin install")
121121
if err != nil {
122122
return err
123123
}
124-
responseBody, err := dockerCli.Client().PluginInstall(ctx, localName, options)
124+
responseBody, err := dockerCLI.Client().PluginInstall(ctx, localName, options)
125125
if err != nil {
126126
if strings.Contains(err.Error(), "(image) when fetching") {
127127
return errors.New(err.Error() + " - Use \"docker image pull\"")
128128
}
129129
return err
130130
}
131131
defer responseBody.Close()
132-
if err := jsonstream.Display(ctx, responseBody, dockerCli.Out()); err != nil {
132+
if err := jsonstream.Display(ctx, responseBody, dockerCLI.Out()); err != nil {
133133
return err
134134
}
135-
fmt.Fprintf(dockerCli.Out(), "Installed plugin %s\n", opts.remote) // todo: return proper values from the API for this result
135+
_, _ = fmt.Fprintln(dockerCLI.Out(), "Installed plugin", opts.remote) // todo: return proper values from the API for this result
136136
return nil
137137
}
138138

139-
func acceptPrivileges(dockerCli command.Cli, name string) func(ctx context.Context, privileges types.PluginPrivileges) (bool, error) {
139+
func acceptPrivileges(dockerCLI command.Cli, name string) func(ctx context.Context, privileges types.PluginPrivileges) (bool, error) {
140140
return func(ctx context.Context, privileges types.PluginPrivileges) (bool, error) {
141-
fmt.Fprintf(dockerCli.Out(), "Plugin %q is requesting the following privileges:\n", name)
141+
_, _ = fmt.Fprintf(dockerCLI.Out(), "Plugin %q is requesting the following privileges:\n", name)
142142
for _, privilege := range privileges {
143-
fmt.Fprintf(dockerCli.Out(), " - %s: %v\n", privilege.Name, privilege.Value)
143+
_, _ = fmt.Fprintf(dockerCLI.Out(), " - %s: %v\n", privilege.Name, privilege.Value)
144144
}
145-
return command.PromptForConfirmation(ctx, dockerCli.In(), dockerCli.Out(), "Do you grant the above permissions?")
145+
return command.PromptForConfirmation(ctx, dockerCLI.In(), dockerCLI.Out(), "Do you grant the above permissions?")
146146
}
147147
}

cli/command/plugin/upgrade.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func newUpgradeCommand(dockerCli command.Cli) *cobra.Command {
3636
return cmd
3737
}
3838

39-
func runUpgrade(ctx context.Context, dockerCli command.Cli, opts pluginOptions) error {
40-
p, _, err := dockerCli.Client().PluginInspectWithRaw(ctx, opts.localName)
39+
func runUpgrade(ctx context.Context, dockerCLI command.Cli, opts pluginOptions) error {
40+
p, _, err := dockerCLI.Client().PluginInspectWithRaw(ctx, opts.localName)
4141
if err != nil {
4242
return errors.Errorf("error reading plugin data: %v", err)
4343
}
@@ -62,9 +62,9 @@ func runUpgrade(ctx context.Context, dockerCli command.Cli, opts pluginOptions)
6262
}
6363
old = reference.TagNameOnly(old)
6464

65-
fmt.Fprintf(dockerCli.Out(), "Upgrading plugin %s from %s to %s\n", p.Name, reference.FamiliarString(old), reference.FamiliarString(remote))
65+
_, _ = fmt.Fprintf(dockerCLI.Out(), "Upgrading plugin %s from %s to %s\n", p.Name, reference.FamiliarString(old), reference.FamiliarString(remote))
6666
if !opts.skipRemoteCheck && remote.String() != old.String() {
67-
r, err := command.PromptForConfirmation(ctx, dockerCli.In(), dockerCli.Out(), "Plugin images do not match, are you sure?")
67+
r, err := command.PromptForConfirmation(ctx, dockerCLI.In(), dockerCLI.Out(), "Plugin images do not match, are you sure?")
6868
if err != nil {
6969
return err
7070
}
@@ -73,22 +73,22 @@ func runUpgrade(ctx context.Context, dockerCli command.Cli, opts pluginOptions)
7373
}
7474
}
7575

76-
options, err := buildPullConfig(ctx, dockerCli, opts, "plugin upgrade")
76+
options, err := buildPullConfig(ctx, dockerCLI, opts, "plugin upgrade")
7777
if err != nil {
7878
return err
7979
}
8080

81-
responseBody, err := dockerCli.Client().PluginUpgrade(ctx, opts.localName, options)
81+
responseBody, err := dockerCLI.Client().PluginUpgrade(ctx, opts.localName, options)
8282
if err != nil {
8383
if strings.Contains(err.Error(), "target is image") {
8484
return errors.New(err.Error() + " - Use `docker image pull`")
8585
}
8686
return err
8787
}
8888
defer responseBody.Close()
89-
if err := jsonstream.Display(ctx, responseBody, dockerCli.Out()); err != nil {
89+
if err := jsonstream.Display(ctx, responseBody, dockerCLI.Out()); err != nil {
9090
return err
9191
}
92-
fmt.Fprintf(dockerCli.Out(), "Upgraded plugin %s to %s\n", opts.localName, opts.remote) // todo: return proper values from the API for this result
92+
_, _ = fmt.Fprintf(dockerCLI.Out(), "Upgraded plugin %s to %s\n", opts.localName, opts.remote) // todo: return proper values from the API for this result
9393
return nil
9494
}

0 commit comments

Comments
 (0)