Skip to content

Commit aa74f93

Browse files
committed
cli/command/service: minor cleanups: use Println, rename vars
- use Println to print newline instead of custom format - use apiClient instead of client for the API client to prevent shadowing imports. - 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 016dbef commit aa74f93

6 files changed

Lines changed: 28 additions & 28 deletions

File tree

cli/command/service/create.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
7878
return cmd
7979
}
8080

81-
func runCreate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, opts *serviceOptions) error {
82-
apiClient := dockerCli.Client()
81+
func runCreate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts *serviceOptions) error {
82+
apiClient := dockerCLI.Client()
8383
createOpts := types.ServiceCreateOptions{}
8484

8585
service, err := opts.ToService(ctx, apiClient, flags)
8686
if err != nil {
8787
return err
8888
}
8989

90-
if err = validateAPIVersion(service, dockerCli.Client().ClientVersion()); err != nil {
90+
if err = validateAPIVersion(service, dockerCLI.Client().ClientVersion()); err != nil {
9191
return err
9292
}
9393

@@ -105,14 +105,14 @@ func runCreate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
105105
return err
106106
}
107107

108-
if err := resolveServiceImageDigestContentTrust(dockerCli, &service); err != nil {
108+
if err := resolveServiceImageDigestContentTrust(dockerCLI, &service); err != nil {
109109
return err
110110
}
111111

112112
// only send auth if flag was set
113113
if opts.registryAuth {
114114
// Retrieve encoded auth token from the image reference
115-
encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCli.ConfigFile(), opts.image)
115+
encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCLI.ConfigFile(), opts.image)
116116
if err != nil {
117117
return err
118118
}
@@ -130,16 +130,16 @@ func runCreate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
130130
}
131131

132132
for _, warning := range response.Warnings {
133-
fmt.Fprintln(dockerCli.Err(), warning)
133+
_, _ = fmt.Fprintln(dockerCLI.Err(), warning)
134134
}
135135

136-
fmt.Fprintf(dockerCli.Out(), "%s\n", response.ID)
136+
_, _ = fmt.Fprintln(dockerCLI.Out(), response.ID)
137137

138138
if opts.detach || versions.LessThan(apiClient.ClientVersion(), "1.29") {
139139
return nil
140140
}
141141

142-
return WaitOnService(ctx, dockerCli, response.ID, opts.quiet)
142+
return WaitOnService(ctx, dockerCLI, response.ID, opts.quiet)
143143
}
144144

145145
// setConfigs does double duty: it both sets the ConfigReferences of the

cli/command/service/remove.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
2929
return cmd
3030
}
3131

32-
func runRemove(ctx context.Context, dockerCli command.Cli, sids []string) error {
33-
client := dockerCli.Client()
32+
func runRemove(ctx context.Context, dockerCLI command.Cli, serviceIDs []string) error {
33+
apiClient := dockerCLI.Client()
3434

3535
var errs []string
36-
for _, sid := range sids {
37-
err := client.ServiceRemove(ctx, sid)
36+
for _, id := range serviceIDs {
37+
err := apiClient.ServiceRemove(ctx, id)
3838
if err != nil {
3939
errs = append(errs, err.Error())
4040
continue
4141
}
42-
_, _ = fmt.Fprintf(dockerCli.Out(), "%s\n", sid)
42+
_, _ = fmt.Fprintln(dockerCLI.Out(), id)
4343
}
4444
if len(errs) > 0 {
4545
return errors.New(strings.Join(errs, "\n"))

cli/command/service/rollback.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func newRollbackCommand(dockerCli command.Cli) *cobra.Command {
3434
return cmd
3535
}
3636

37-
func runRollback(ctx context.Context, dockerCli command.Cli, options *serviceOptions, serviceID string) error {
38-
apiClient := dockerCli.Client()
37+
func runRollback(ctx context.Context, dockerCLI command.Cli, options *serviceOptions, serviceID string) error {
38+
apiClient := dockerCLI.Client()
3939

4040
service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, types.ServiceInspectOptions{})
4141
if err != nil {
@@ -53,14 +53,14 @@ func runRollback(ctx context.Context, dockerCli command.Cli, options *serviceOpt
5353
}
5454

5555
for _, warning := range response.Warnings {
56-
fmt.Fprintln(dockerCli.Err(), warning)
56+
_, _ = fmt.Fprintln(dockerCLI.Err(), warning)
5757
}
5858

59-
fmt.Fprintf(dockerCli.Out(), "%s\n", serviceID)
59+
_, _ = fmt.Fprintln(dockerCLI.Out(), serviceID)
6060

6161
if options.detach || versions.LessThan(apiClient.ClientVersion(), "1.29") {
6262
return nil
6363
}
6464

65-
return WaitOnService(ctx, dockerCli, serviceID, options.quiet)
65+
return WaitOnService(ctx, dockerCLI, serviceID, options.quiet)
6666
}

cli/command/service/scale.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ func runServiceScale(ctx context.Context, dockerCli command.Cli, serviceID strin
117117
}
118118

119119
for _, warning := range response.Warnings {
120-
fmt.Fprintln(dockerCli.Err(), warning)
120+
_, _ = fmt.Fprintln(dockerCli.Err(), warning)
121121
}
122122

123-
fmt.Fprintf(dockerCli.Out(), "%s scaled to %d\n", serviceID, scale)
123+
_, _ = fmt.Fprintf(dockerCli.Out(), "%s scaled to %d\n", serviceID, scale)
124124
return nil
125125
}

cli/command/service/trust.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func trustedResolveDigest(cli command.Cli, ref reference.NamedTagged) (reference
7373
return nil, trust.NotaryError(repoInfo.Name.Name(), errors.Errorf("No trust data for %s", reference.FamiliarString(ref)))
7474
}
7575

76-
logrus.Debugf("retrieving target for %s role\n", t.Role)
76+
logrus.Debugf("retrieving target for %s role", t.Role)
7777
h, ok := t.Hashes["sha256"]
7878
if !ok {
7979
return nil, errors.New("no valid hash, expecting sha256")

cli/command/service/update.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ func newListOptsVarWithValidator(validator opts.ValidatorFctType) *opts.ListOpts
129129
}
130130

131131
//nolint:gocyclo
132-
func runUpdate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, options *serviceOptions, serviceID string) error {
133-
apiClient := dockerCli.Client()
132+
func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, options *serviceOptions, serviceID string) error {
133+
apiClient := dockerCLI.Client()
134134

135135
service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, types.ServiceInspectOptions{})
136136
if err != nil {
@@ -188,7 +188,7 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
188188
}
189189

190190
if flags.Changed("image") {
191-
if err := resolveServiceImageDigestContentTrust(dockerCli, spec); err != nil {
191+
if err := resolveServiceImageDigestContentTrust(dockerCLI, spec); err != nil {
192192
return err
193193
}
194194
if !options.noResolveImage && versions.GreaterThanOrEqualTo(apiClient.ClientVersion(), "1.30") {
@@ -225,7 +225,7 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
225225
// Retrieve encoded auth token from the image reference
226226
// This would be the old image if it didn't change in this update
227227
image := spec.TaskTemplate.ContainerSpec.Image
228-
encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCli.ConfigFile(), image)
228+
encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCLI.ConfigFile(), image)
229229
if err != nil {
230230
return err
231231
}
@@ -242,16 +242,16 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
242242
}
243243

244244
for _, warning := range response.Warnings {
245-
fmt.Fprintln(dockerCli.Err(), warning)
245+
_, _ = fmt.Fprintln(dockerCLI.Err(), warning)
246246
}
247247

248-
fmt.Fprintf(dockerCli.Out(), "%s\n", serviceID)
248+
_, _ = fmt.Fprintln(dockerCLI.Out(), serviceID)
249249

250250
if options.detach || versions.LessThan(apiClient.ClientVersion(), "1.29") {
251251
return nil
252252
}
253253

254-
return WaitOnService(ctx, dockerCli, serviceID, options.quiet)
254+
return WaitOnService(ctx, dockerCLI, serviceID, options.quiet)
255255
}
256256

257257
//nolint:gocyclo

0 commit comments

Comments
 (0)