Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/auto-install-missing-version
- Loading branch information
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/tfversion/tfversion/pkg/current" | ||
) | ||
|
||
const ( | ||
currentExample = "# Print the current active version of Terraform\n" + | ||
"tfversion current" | ||
) | ||
|
||
var ( | ||
currentCmd = &cobra.Command{ | ||
Use: "current", | ||
Short: "Print the current active version of Terraform", | ||
Example: currentExample, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
current.CheckCurrentVersion() | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(currentCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package current | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/tfversion/tfversion/pkg/download" | ||
"github.com/tfversion/tfversion/pkg/helpers" | ||
"github.com/tfversion/tfversion/pkg/use" | ||
) | ||
|
||
// CheckCurrentVersion prints the current active version of Terraform. | ||
func CheckCurrentVersion() { | ||
|
||
symlinkPath := filepath.Join(use.GetUseLocation(), download.TerraformBinaryName) | ||
_, err := os.Lstat(symlinkPath) | ||
if err != nil { | ||
helpers.ExitWithError("no current terraform version found", err) | ||
} | ||
|
||
realPath, err := filepath.EvalSymlinks(symlinkPath) | ||
if err != nil { | ||
helpers.ExitWithError("resolving symlink", err) | ||
} | ||
_, currentVersion := filepath.Split(filepath.Dir(realPath)) | ||
|
||
fmt.Printf("Current active Terraform version: %s\n", helpers.ColoredVersion(currentVersion)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters