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

cli: allow suppressing deprecation warning #2247

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions aci/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
package aci

import (
"fmt"
"os"
"strings"

"github.com/docker/compose-cli/utils"

"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2019-12-01/containerinstance"
"github.com/Azure/go-autorest/autorest/to"
"github.com/docker/compose/v2/pkg/api"
Expand Down Expand Up @@ -69,7 +70,7 @@ func init() {
}

func service() (backend.Service, error) {
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/")
utils.ShowDeprecationWarning(os.Stderr)
contextStore := store.Instance()
currentContext := apicontext.Current()
var aciContext store.AciContext
Expand Down
5 changes: 3 additions & 2 deletions aci/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package aci

import (
"context"
"fmt"
"os"

"github.com/docker/compose-cli/utils"

"github.com/pkg/errors"

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

func (cs *aciCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
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/")
utils.ShowDeprecationWarning(os.Stderr)
contextHelper := newContextCreateHelper()
createOpts := params.(ContextParams)
return contextHelper.createContextData(ctx, createOpts)
Expand Down
6 changes: 4 additions & 2 deletions ecs/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"os"

"github.com/docker/compose-cli/utils"

"github.com/docker/compose-cli/api/backend"
"github.com/docker/compose-cli/api/cloud"
"github.com/docker/compose-cli/api/containers"
Expand Down Expand Up @@ -63,7 +65,7 @@ func init() {
}

func service() (backend.Service, error) {
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/")
utils.ShowDeprecationWarning(os.Stderr)
contextStore := store.Instance()
currentContext := apicontext.Current()
var ecsContext store.EcsContext
Expand Down Expand Up @@ -157,7 +159,7 @@ func (a ecsCloudService) Logout(ctx context.Context) error {
}

func (a ecsCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
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/")
utils.ShowDeprecationWarning(os.Stderr)
contextHelper := newContextCreateHelper()
createOpts := params.(ContextParams)
return contextHelper.createContextData(ctx, createOpts)
Expand Down
38 changes: 38 additions & 0 deletions utils/deprecation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2020 Docker Compose CLI authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package utils

import (
"fmt"
"io"
"os"
"strconv"
"sync"
)

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/"

var warnOnce sync.Once

func ShowDeprecationWarning(w io.Writer) {
warnOnce.Do(func() {
if quiet, _ := strconv.ParseBool(os.Getenv("COMPOSE_CLOUD_EOL_SILENT")); quiet {
return
}
_, _ = fmt.Fprintln(w, deprecationMessage)
})
}