cli/command: rename vars for consistency and prevent shadowing

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-23 01:43:04 +02:00
parent 1df8feb2e4
commit 9fd71c8347
30 changed files with 180 additions and 186 deletions

View File

@ -54,10 +54,10 @@ func newCACommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
func runCA(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, opts caOptions) error {
client := dockerCli.Client()
func runCA(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts caOptions) error {
apiClient := dockerCLI.Client()
swarmInspect, err := client.SwarmInspect(ctx)
swarmInspect, err := apiClient.SwarmInspect(ctx)
if err != nil {
return err
}
@ -68,7 +68,7 @@ func runCA(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, opt
return fmt.Errorf("`--%s` flag requires the `--rotate` flag to update the CA", f)
}
}
return displayTrustRoot(dockerCli.Out(), swarmInspect)
return displayTrustRoot(dockerCLI.Out(), swarmInspect)
}
if flags.Changed(flagExternalCA) && len(opts.externalCA.Value()) > 0 && !flags.Changed(flagCACert) {
@ -83,14 +83,14 @@ func runCA(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, opt
}
updateSwarmSpec(&swarmInspect.Spec, flags, opts)
if err := client.SwarmUpdate(ctx, swarmInspect.Version, swarmInspect.Spec, swarm.UpdateFlags{}); err != nil {
if err := apiClient.SwarmUpdate(ctx, swarmInspect.Version, swarmInspect.Spec, swarm.UpdateFlags{}); err != nil {
return err
}
if opts.detach {
return nil
}
return attach(ctx, dockerCli, opts)
return attach(ctx, dockerCLI, opts)
}
func updateSwarmSpec(spec *swarm.Spec, flags *pflag.FlagSet, opts caOptions) {
@ -106,13 +106,13 @@ func updateSwarmSpec(spec *swarm.Spec, flags *pflag.FlagSet, opts caOptions) {
}
}
func attach(ctx context.Context, dockerCli command.Cli, opts caOptions) error {
client := dockerCli.Client()
func attach(ctx context.Context, dockerCLI command.Cli, opts caOptions) error {
apiClient := dockerCLI.Client()
errChan := make(chan error, 1)
pipeReader, pipeWriter := io.Pipe()
go func() {
errChan <- progress.RootRotationProgress(ctx, client, pipeWriter)
errChan <- progress.RootRotationProgress(ctx, apiClient, pipeWriter)
}()
if opts.quiet {
@ -120,7 +120,7 @@ func attach(ctx context.Context, dockerCli command.Cli, opts caOptions) error {
return <-errChan
}
err := jsonstream.Display(ctx, pipeReader, dockerCli.Out())
err := jsonstream.Display(ctx, pipeReader, dockerCLI.Out())
if err == nil {
err = <-errChan
}
@ -128,17 +128,17 @@ func attach(ctx context.Context, dockerCli command.Cli, opts caOptions) error {
return err
}
swarmInspect, err := client.SwarmInspect(ctx)
swarmInspect, err := apiClient.SwarmInspect(ctx)
if err != nil {
return err
}
return displayTrustRoot(dockerCli.Out(), swarmInspect)
return displayTrustRoot(dockerCLI.Out(), swarmInspect)
}
func displayTrustRoot(out io.Writer, info swarm.Swarm) error {
if info.ClusterInfo.TLSInfo.TrustRoot == "" {
return errors.New("No CA information available")
}
fmt.Fprintln(out, strings.TrimSpace(info.ClusterInfo.TLSInfo.TrustRoot))
_, _ = fmt.Fprintln(out, strings.TrimSpace(info.ClusterInfo.TLSInfo.TrustRoot))
return nil
}

View File

@ -52,8 +52,8 @@ func newJoinCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
func runJoin(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, opts joinOptions) error {
client := dockerCli.Client()
func runJoin(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts joinOptions) error {
apiClient := dockerCLI.Client()
req := swarm.JoinRequest{
JoinToken: opts.token,
@ -72,20 +72,20 @@ func runJoin(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, o
}
}
err := client.SwarmJoin(ctx, req)
err := apiClient.SwarmJoin(ctx, req)
if err != nil {
return err
}
info, err := client.Info(ctx)
info, err := apiClient.Info(ctx)
if err != nil {
return err
}
if info.Swarm.ControlAvailable {
fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a manager.")
_, _ = fmt.Fprintln(dockerCLI.Out(), "This node joined a swarm as a manager.")
} else {
fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a worker.")
_, _ = fmt.Fprintln(dockerCLI.Out(), "This node joined a swarm as a worker.")
}
return nil
}

View File

@ -36,13 +36,13 @@ func newLeaveCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
func runLeave(ctx context.Context, dockerCli command.Cli, opts leaveOptions) error {
client := dockerCli.Client()
func runLeave(ctx context.Context, dockerCLI command.Cli, opts leaveOptions) error {
apiClient := dockerCLI.Client()
if err := client.SwarmLeave(ctx, opts.force); err != nil {
if err := apiClient.SwarmLeave(ctx, opts.force); err != nil {
return err
}
fmt.Fprintln(dockerCli.Out(), "Node left the swarm.")
_, _ = fmt.Fprintln(dockerCLI.Out(), "Node left the swarm.")
return nil
}

View File

@ -35,12 +35,12 @@ func newUnlockCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
func runUnlock(ctx context.Context, dockerCli command.Cli) error {
client := dockerCli.Client()
func runUnlock(ctx context.Context, dockerCLI command.Cli) error {
apiClient := dockerCLI.Client()
// First see if the node is actually part of a swarm, and if it is actually locked first.
// If it's in any other state than locked, don't ask for the key.
info, err := client.Info(ctx)
info, err := apiClient.Info(ctx)
if err != nil {
return err
}
@ -54,12 +54,12 @@ func runUnlock(ctx context.Context, dockerCli command.Cli) error {
return errors.New("Error: swarm is not locked")
}
key, err := readKey(dockerCli.In(), "Enter unlock key: ")
key, err := readKey(dockerCLI.In(), "Enter unlock key: ")
if err != nil {
return err
}
return client.SwarmUnlock(ctx, swarm.UnlockRequest{
return apiClient.SwarmUnlock(ctx, swarm.UnlockRequest{
UnlockKey: key,
})
}

View File

@ -41,12 +41,12 @@ func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
return cmd
}
func runUpdate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, opts swarmOptions) error {
client := dockerCli.Client()
func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts swarmOptions) error {
apiClient := dockerCLI.Client()
var updateFlags swarm.UpdateFlags
swarmInspect, err := client.SwarmInspect(ctx)
swarmInspect, err := apiClient.SwarmInspect(ctx)
if err != nil {
return err
}
@ -57,19 +57,19 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
curAutoLock := swarmInspect.Spec.EncryptionConfig.AutoLockManagers
err = client.SwarmUpdate(ctx, swarmInspect.Version, swarmInspect.Spec, updateFlags)
err = apiClient.SwarmUpdate(ctx, swarmInspect.Version, swarmInspect.Spec, updateFlags)
if err != nil {
return err
}
fmt.Fprintln(dockerCli.Out(), "Swarm updated.")
_, _ = fmt.Fprintln(dockerCLI.Out(), "Swarm updated.")
if curAutoLock && !prevAutoLock {
unlockKeyResp, err := client.SwarmGetUnlockKey(ctx)
unlockKeyResp, err := apiClient.SwarmGetUnlockKey(ctx)
if err != nil {
return errors.Wrap(err, "could not fetch unlock key")
}
printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey)
printUnlockCommand(dockerCLI.Out(), unlockKeyResp.UnlockKey)
}
return nil