Skip to content

Commit

Permalink
Adding sanitation for the use command to make sure a file exists first
Browse files Browse the repository at this point in the history
  • Loading branch information
simplyzee committed Sep 18, 2019
1 parent 00c4807 commit ddc5e66
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
/vendor/
/Godeps/

### VSCode ###
.vscode

### JetBrains ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Expand Down Expand Up @@ -105,4 +108,4 @@ fabric.properties
# Sonarlint plugin
.idea/sonarlint

# End of https://www.gitignore.io/api/go,jetbrains
# End of https://www.gitignore.io/api/go,jetbrains
8 changes: 7 additions & 1 deletion cmd/use_darwin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin
// +build linux

/*
Copyright © 2019 Zee Ahmed <zee@simplyzee.dev>
Expand Down Expand Up @@ -62,6 +62,12 @@ func UseKubectlBinary(version string) error {
kubectlVersion := homeDir + "/.kubemngr/kubectl-" + version
kubectlLink := homeDir + "/.local/bin/kubectl"

_, err = os.Stat(kubectlVersion)
if os.IsNotExist(err) {
log.Printf("kubectl %s does not exist", version)
os.Exit(1)
}

if _, err := os.Lstat(kubectlLink); err == nil {
os.Remove(kubectlLink)
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/use_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ func UseKubectlBinary(version string) error {
kubectlVersion := homeDir + "/.kubemngr/kubectl-" + version
kubectlLink := homeDir + "/.local/bin/kubectl"

_, err = os.Stat(kubectlVersion)
if os.IsNotExist(err) {
log.Printf("kubectl %s does not exist", version)
os.Exit(1)
}

if _, err := os.Lstat(kubectlLink); err == nil {
os.Remove(kubectlLink)
}
Expand Down

0 comments on commit ddc5e66

Please sign in to comment.