Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 5593ef3

Browse files
committed
cli: allow suppressing deprecation warning
Signed-off-by: Milas Bowman <[email protected]>
1 parent 9b21f9a commit 5593ef3

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

aci/backend.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
package aci
1818

1919
import (
20-
"fmt"
2120
"os"
2221
"strings"
2322

23+
"github.com/docker/compose-cli/utils"
24+
2425
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2019-12-01/containerinstance"
2526
"github.com/Azure/go-autorest/autorest/to"
2627
"github.com/docker/compose/v2/pkg/api"
@@ -69,7 +70,7 @@ func init() {
6970
}
7071

7172
func service() (backend.Service, error) {
72-
fmt.Fprintln(os.Stderr, "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/")
73+
utils.ShowDeprecationWarning(os.Stderr)
7374
contextStore := store.Instance()
7475
currentContext := apicontext.Current()
7576
var aciContext store.AciContext

aci/cloud.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ package aci
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"os"
2322

23+
"github.com/docker/compose-cli/utils"
24+
2425
"github.com/pkg/errors"
2526

2627
"github.com/docker/compose-cli/aci/login"
@@ -49,7 +50,7 @@ func (cs *aciCloudService) Logout(ctx context.Context) error {
4950
}
5051

5152
func (cs *aciCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
52-
fmt.Fprintln(os.Stderr, "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/")
53+
utils.ShowDeprecationWarning(os.Stderr)
5354
contextHelper := newContextCreateHelper()
5455
createOpts := params.(ContextParams)
5556
return contextHelper.createContextData(ctx, createOpts)

ecs/backend.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"fmt"
2222
"os"
2323

24+
"github.com/docker/compose-cli/utils"
25+
2426
"github.com/docker/compose-cli/api/backend"
2527
"github.com/docker/compose-cli/api/cloud"
2628
"github.com/docker/compose-cli/api/containers"
@@ -63,7 +65,7 @@ func init() {
6365
}
6466

6567
func service() (backend.Service, error) {
66-
fmt.Fprintln(os.Stderr, "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/")
68+
utils.ShowDeprecationWarning(os.Stderr)
6769
contextStore := store.Instance()
6870
currentContext := apicontext.Current()
6971
var ecsContext store.EcsContext
@@ -157,7 +159,7 @@ func (a ecsCloudService) Logout(ctx context.Context) error {
157159
}
158160

159161
func (a ecsCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
160-
fmt.Fprintln(os.Stderr, "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/")
162+
utils.ShowDeprecationWarning(os.Stderr)
161163
contextHelper := newContextCreateHelper()
162164
createOpts := params.(ContextParams)
163165
return contextHelper.createContextData(ctx, createOpts)

utils/deprecation.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package utils
18+
19+
import (
20+
"fmt"
21+
"io"
22+
"os"
23+
"strconv"
24+
"sync"
25+
)
26+
27+
const deprecationMessage = "Docker Compose's integration for ECS and ACI will be retired in November 2023. Learn more: https://docs.docker.com/go/compose-ecs-eol/"
28+
29+
var warnOnce sync.Once
30+
31+
func ShowDeprecationWarning(w io.Writer) {
32+
warnOnce.Do(func() {
33+
if quiet, _ := strconv.ParseBool(os.Getenv("COMPOSE_CLOUD_EOL_SILENT")); quiet {
34+
return
35+
}
36+
_, _ = fmt.Fprintln(w, deprecationMessage)
37+
})
38+
}

0 commit comments

Comments
 (0)