(ctx context.Context, apiClient client.ServiceAPIClient, serviceID string, scale uint64)
| 93 | } |
| 94 | |
| 95 | func runServiceScale(ctx context.Context, apiClient client.ServiceAPIClient, serviceID string, scale uint64) (warnings []string, _ error) { |
| 96 | res, err := apiClient.ServiceInspect(ctx, serviceID, client.ServiceInspectOptions{}) |
| 97 | if err != nil { |
| 98 | return nil, err |
| 99 | } |
| 100 | |
| 101 | serviceMode := &res.Service.Spec.Mode |
| 102 | switch { |
| 103 | case serviceMode.Replicated != nil: |
| 104 | serviceMode.Replicated.Replicas = &scale |
| 105 | case serviceMode.ReplicatedJob != nil: |
| 106 | serviceMode.ReplicatedJob.TotalCompletions = &scale |
| 107 | default: |
| 108 | return nil, errors.New("scale can only be used with replicated or replicated-job mode") |
| 109 | } |
| 110 | |
| 111 | response, err := apiClient.ServiceUpdate(ctx, res.Service.ID, client.ServiceUpdateOptions{ |
| 112 | Version: res.Service.Version, |
| 113 | Spec: res.Service.Spec, |
| 114 | }) |
| 115 | if err != nil { |
| 116 | return nil, err |
| 117 | } |
| 118 | return response.Warnings, nil |
| 119 | } |
| 120 | |
| 121 | // completeScaleArgs returns a completion function for the args of the scale command. |
| 122 | // It completes service names followed by "=", suppressing the trailing space. |
no test coverage detected
searching dependent graphs…