Skip to content

Commit

Permalink
deprecated removal #188 (#202)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Vaumoron <[email protected]>
  • Loading branch information
dvaumoron authored Jul 3, 2024
1 parent 25666b3 commit c4670c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 48 deletions.
36 changes: 4 additions & 32 deletions cmd/tenv/subcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ import (

const deprecationMsg = "Direct usage of this subcommand on tenv is deprecated, you should use tofu subcommand instead.\n\n"

func newConstraintCmd(conf *config.Config, versionManager versionmanager.VersionManager, params subCmdParams) *cobra.Command {
func newConstraintCmd(conf *config.Config, versionManager versionmanager.VersionManager) *cobra.Command {
var descBuilder strings.Builder
addDeprecationHelpMsg(&descBuilder, params)
descBuilder.WriteString("Set a default constraint expression for ")
descBuilder.WriteString(versionManager.FolderName)
descBuilder.WriteString(" (set in TENV_ROOT/")
Expand All @@ -55,7 +54,6 @@ The default constraint is added while using latest-allowed, min-required or cust
Args: cobra.MaximumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
conf.InitDisplayer(false)
addDeprecationMsg(conf, params)

if len(args) == 0 || args[0] == "" {
if err := versionManager.ResetConstraint(); err != nil {
Expand All @@ -76,7 +74,6 @@ The default constraint is added while using latest-allowed, min-required or cust

func newDetectCmd(conf *config.Config, versionManager versionmanager.VersionManager, params subCmdParams) *cobra.Command {
var descBuilder strings.Builder
addDeprecationHelpMsg(&descBuilder, params)
descBuilder.WriteString("Display ")
descBuilder.WriteString(versionManager.FolderName)
descBuilder.WriteString(" current version.")
Expand All @@ -91,7 +88,6 @@ func newDetectCmd(conf *config.Config, versionManager versionmanager.VersionMana
Run: func(_ *cobra.Command, _ []string) {
conf.InitDisplayer(false)
conf.InitInstall(forceInstall, forceNoInstall)
addDeprecationMsg(conf, params)

detectedVersion, err := versionManager.Detect(false)
if err != nil {
Expand All @@ -115,7 +111,6 @@ func newDetectCmd(conf *config.Config, versionManager versionmanager.VersionMana

func newInstallCmd(conf *config.Config, versionManager versionmanager.VersionManager, params subCmdParams) *cobra.Command {
var descBuilder strings.Builder
addDeprecationHelpMsg(&descBuilder, params)
descBuilder.WriteString("Install a specific version of ")
descBuilder.WriteString(versionManager.FolderName)
descBuilder.WriteString(" (into TENV_ROOT directory from ")
Expand Down Expand Up @@ -143,7 +138,6 @@ If a parameter is passed, available options:
Args: cobra.MaximumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
conf.InitDisplayer(false)
addDeprecationMsg(conf, params)

if len(args) == 0 {
version, err := versionManager.Resolve(semantic.LatestKey)
Expand Down Expand Up @@ -173,9 +167,8 @@ If a parameter is passed, available options:
return installCmd
}

func newListCmd(conf *config.Config, versionManager versionmanager.VersionManager, params subCmdParams) *cobra.Command {
func newListCmd(conf *config.Config, versionManager versionmanager.VersionManager) *cobra.Command {
var descBuilder strings.Builder
addDeprecationHelpMsg(&descBuilder, params)
descBuilder.WriteString("List installed ")
descBuilder.WriteString(versionManager.FolderName)
descBuilder.WriteString(" versions (located in TENV_ROOT directory), sorted in ascending version order.")
Expand All @@ -189,7 +182,6 @@ func newListCmd(conf *config.Config, versionManager versionmanager.VersionManage
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
conf.InitDisplayer(false)
addDeprecationMsg(conf, params)

versions, err := versionManager.ListLocal(reverseOrder)
if err != nil {
Expand Down Expand Up @@ -225,7 +217,6 @@ func newListCmd(conf *config.Config, versionManager versionmanager.VersionManage

func newListRemoteCmd(conf *config.Config, versionManager versionmanager.VersionManager, params subCmdParams) *cobra.Command {
var descBuilder strings.Builder
addDeprecationHelpMsg(&descBuilder, params)
descBuilder.WriteString("List installable ")
descBuilder.WriteString(versionManager.FolderName)
descBuilder.WriteString(" versions (from ")
Expand All @@ -242,7 +233,6 @@ func newListRemoteCmd(conf *config.Config, versionManager versionmanager.Version
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
conf.InitDisplayer(false)
addDeprecationMsg(conf, params)

versions, err := versionManager.ListRemote(reverseOrder)
if err != nil {
Expand Down Expand Up @@ -285,9 +275,8 @@ func newListRemoteCmd(conf *config.Config, versionManager versionmanager.Version
return listRemoteCmd
}

func newResetCmd(conf *config.Config, versionManager versionmanager.VersionManager, params subCmdParams) *cobra.Command {
func newResetCmd(conf *config.Config, versionManager versionmanager.VersionManager) *cobra.Command {
var descBuilder strings.Builder
addDeprecationHelpMsg(&descBuilder, params)
descBuilder.WriteString("Reset used version of ")
descBuilder.WriteString(versionManager.FolderName)
descBuilder.WriteString(" (remove TENV_ROOT/")
Expand All @@ -301,7 +290,6 @@ func newResetCmd(conf *config.Config, versionManager versionmanager.VersionManag
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
conf.InitDisplayer(false)
addDeprecationMsg(conf, params)

if err := versionManager.ResetVersion(); err != nil {
loghelper.StdDisplay(err.Error())
Expand All @@ -312,9 +300,8 @@ func newResetCmd(conf *config.Config, versionManager versionmanager.VersionManag
return resetCmd
}

func newUninstallCmd(conf *config.Config, versionManager versionmanager.VersionManager, params subCmdParams) *cobra.Command {
func newUninstallCmd(conf *config.Config, versionManager versionmanager.VersionManager) *cobra.Command {
var descBuilder strings.Builder
addDeprecationHelpMsg(&descBuilder, params)
descBuilder.WriteString("Uninstall a specific version of ")
descBuilder.WriteString(versionManager.FolderName)
descBuilder.WriteString(" (remove it from TENV_ROOT directory).")
Expand All @@ -326,7 +313,6 @@ func newUninstallCmd(conf *config.Config, versionManager versionmanager.VersionM
Args: cobra.ExactArgs(1),
Run: func(_ *cobra.Command, args []string) {
conf.InitDisplayer(false)
addDeprecationMsg(conf, params)

if err := versionManager.Uninstall(args[0]); err != nil {
loghelper.StdDisplay(err.Error())
Expand All @@ -339,7 +325,6 @@ func newUninstallCmd(conf *config.Config, versionManager versionmanager.VersionM

func newUseCmd(conf *config.Config, versionManager versionmanager.VersionManager, params subCmdParams) *cobra.Command {
var descBuilder strings.Builder
addDeprecationHelpMsg(&descBuilder, params)
descBuilder.WriteString("Switch the default ")
descBuilder.WriteString(versionManager.FolderName)
descBuilder.WriteString(" version to use (set in TENV_ROOT/")
Expand All @@ -365,7 +350,6 @@ Available parameter options:
Run: func(_ *cobra.Command, args []string) {
conf.InitDisplayer(false)
conf.InitInstall(forceInstall, forceNoInstall)
addDeprecationMsg(conf, params)

if err := versionManager.Use(args[0], workingDir); err != nil {
loghelper.StdDisplay(err.Error())
Expand All @@ -382,18 +366,6 @@ Available parameter options:
return useCmd
}

func addDeprecationHelpMsg(descBuilder *strings.Builder, params subCmdParams) {
if params.deprecated {
descBuilder.WriteString(deprecationMsg)
}
}

func addDeprecationMsg(conf *config.Config, params subCmdParams) {
if params.deprecated {
conf.Displayer.Display(deprecationMsg)
}
}

func addDescendingFlag(flags *pflag.FlagSet, pReverseOrder *bool) {
flags.BoolVarP(pReverseOrder, "descending", "d", false, "display list in descending version order")
}
Expand Down
27 changes: 11 additions & 16 deletions cmd/tenv/tenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const (
var version = "dev"

type subCmdParams struct {
deprecated bool
needToken bool
remoteEnvName string
pRemote *string
Expand Down Expand Up @@ -97,24 +96,20 @@ func initRootCmd(conf *config.Config, builders map[string]builder.BuilderFunc, h
rootCmd.AddCommand(newVersionCmd())
rootCmd.AddCommand(newUpdatePathCmd(conf.GithubActions))

tofuParams := subCmdParams{
deprecated: true, // direct use should display a deprecation message
needToken: true, remoteEnvName: config.TofuRemoteURLEnvName,
pRemote: &conf.Tofu.RemoteURL, pPublicKeyPath: &conf.TofuKeyPath,
}
tofuManager := builders[cmdconst.TofuName](conf, hclParser)
initSubCmds(rootCmd, conf, tofuManager, tofuParams) // add tofu management at root level

tofuCmd := &cobra.Command{
Use: cmdconst.TofuName,
Aliases: []string{"opentofu"},
Short: tofuHelp,
Long: tofuHelp,
}
tofuParams.deprecated = false // usage with tofu subcommand are ok
initSubCmds(tofuCmd, conf, tofuManager, tofuParams)

rootCmd.AddCommand(tofuCmd) // add tofu management as subcommand
tofuParams := subCmdParams{
needToken: true, remoteEnvName: config.TofuRemoteURLEnvName,
pRemote: &conf.Tofu.RemoteURL, pPublicKeyPath: &conf.TofuKeyPath,
}
initSubCmds(tofuCmd, conf, builders[cmdconst.TofuName](conf, hclParser), tofuParams)

rootCmd.AddCommand(tofuCmd)

tfCmd := &cobra.Command{
Use: "tf",
Expand Down Expand Up @@ -228,12 +223,12 @@ func newUpdatePathCmd(gha bool) *cobra.Command {
}

func initSubCmds(cmd *cobra.Command, conf *config.Config, versionManager versionmanager.VersionManager, params subCmdParams) {
cmd.AddCommand(newConstraintCmd(conf, versionManager, params))
cmd.AddCommand(newConstraintCmd(conf, versionManager))
cmd.AddCommand(newDetectCmd(conf, versionManager, params))
cmd.AddCommand(newInstallCmd(conf, versionManager, params))
cmd.AddCommand(newListCmd(conf, versionManager, params))
cmd.AddCommand(newListCmd(conf, versionManager))
cmd.AddCommand(newListRemoteCmd(conf, versionManager, params))
cmd.AddCommand(newResetCmd(conf, versionManager, params))
cmd.AddCommand(newUninstallCmd(conf, versionManager, params))
cmd.AddCommand(newResetCmd(conf, versionManager))
cmd.AddCommand(newUninstallCmd(conf, versionManager))
cmd.AddCommand(newUseCmd(conf, versionManager, params))
}

0 comments on commit c4670c8

Please sign in to comment.