github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/cli/flags/deprecation.go (about)

     1  package flags
     2  
     3  import (
     4  	"github.com/spf13/cobra"
     5  
     6  	"github.com/telepresenceio/telepresence/v2/pkg/client/cli/output"
     7  	"github.com/telepresenceio/telepresence/v2/pkg/ioutil"
     8  )
     9  
    10  // DeprecationIfChanged will print a deprecation warning on output.Info if the flag has changed.
    11  //
    12  // Use this method instead of the standard pflag deprecation to ensure that the deprecation message
    13  // doesn't clobber JSON output.
    14  func DeprecationIfChanged(cmd *cobra.Command, flagName, alternative string) {
    15  	if flag := cmd.Flag(flagName); flag != nil && flag.Changed {
    16  		ioutil.Printf(output.Info(cmd.Context()), "Flag --%s has been deprecated, %s\n", flagName, alternative)
    17  	}
    18  }