Skip to content

Commit

Permalink
Merge pull request #26 from navilg/25-k8senv-cached-program-locations…
Browse files Browse the repository at this point in the history
…-doesnot-clear-automatically-in-shell

Add a message after use and unuse to clear cached program location
  • Loading branch information
navilg authored May 7, 2023
2 parents b2166e0 + 07c4cde commit 17197db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ k8senv use kubectl 1.26.2
k8senv kubectl use v1.26.2
```

If you were using system installed version of `kubectl` in same shell session, you will need to clear the cached path of the kubectl using below command.

```
hash -d kubectl
```

**Unuse/Disable k8senv managed kubectl**

Any of the below command can be used to unuse or disable k8senv managed kubectl without uninstalling it. This will reset the system to use system installed kubectl, if present.
Expand All @@ -123,6 +129,12 @@ k8senv unuse kubectl
k8senv kubectl unuse
```

To clear the cached k8senv path of kubectl, you will need to clear it using below command before you can use system installed version of the tool.

```
hash -d kubectl
```

**Remove an existing version of kubectl**

Any of below commands can be used to remove kubectl version 1.26.2.
Expand Down
6 changes: 6 additions & 0 deletions internal/unuse/unuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"runtime"

"github.com/navilg/k8senv/internal/config"
)
Expand All @@ -22,6 +23,11 @@ func UnuseVersions(toolname string) error {
if err != nil {
fmt.Println("Failed to unuse", toolname)
fmt.Println("Due to,", err)
return err
}
fmt.Println(toolname, "successfully set to unuse.")
if runtime.GOOS == "linux" {
fmt.Println("Bash shell caches the program location. You might need to run 'hash -d " + toolname + "' to clear it for this to work.")
}
}

Expand Down
6 changes: 6 additions & 0 deletions internal/use/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"runtime"
"strings"

"github.com/navilg/k8senv/internal/config"
Expand Down Expand Up @@ -52,5 +53,10 @@ func UseVersion(toolname, version string) error {

fmt.Println("Using", toolname, version, "as default.")

if runtime.GOOS == "linux" {

fmt.Println("Bash shell caches the program location. You might need to run 'hash -d " + toolname + "' to clear it for this to work.")
}

return nil
}

0 comments on commit 17197db

Please sign in to comment.