Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement tfversion unalias * Fix typo * Move unalias implementation to separate package * Use MkdirAll to ensure all parent dirs are also created * Update function name to remove 'version'
- Loading branch information
1 parent
ad25cd8
commit 25b3a23
Showing
3 changed files
with
63 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/tfversion/tfversion/pkg/helpers" | ||
"github.com/tfversion/tfversion/pkg/unalias" | ||
) | ||
|
||
const ( | ||
unaliasExample = "# Un-alias a Terraform version\n" + | ||
"tfversion unalias default\n" + | ||
"tfversion unalias legacy" | ||
) | ||
|
||
var ( | ||
unaliasCmd = &cobra.Command{ | ||
Use: "unalias", | ||
Short: "Un-alias a Terraform version", | ||
Example: unaliasExample, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 1 { | ||
err := helpers.ErrorWithHelp("tfversion unalias -h") | ||
helpers.ExitWithError("provide an alias name", err) | ||
} | ||
unalias.Unalias(args[0]) | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(unaliasCmd) | ||
} |
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,27 @@ | ||
package unalias | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/tfversion/tfversion/pkg/alias" | ||
"github.com/tfversion/tfversion/pkg/helpers" | ||
) | ||
|
||
// Unalias removes the symlink for the specified alias. | ||
func Unalias(aliasName string) { | ||
aliasLocation := alias.GetAliasLocation() | ||
aliasPath := filepath.Join(aliasLocation, aliasName) | ||
_, err := os.Lstat(aliasPath) | ||
if err != nil { | ||
helpers.ExitWithError("removing symlink", err) | ||
} | ||
|
||
err = os.RemoveAll(aliasPath) | ||
if err != nil { | ||
helpers.ExitWithError("removing symlink", err) | ||
} | ||
|
||
fmt.Printf("Removed alias %s\n", helpers.ColoredVersion(aliasName)) | ||
} |