Skip to content

Commit

Permalink
Replace internal functionality with env module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouture committed Sep 18, 2023
1 parent 9a9c97b commit 90254ef
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 120 deletions.
17 changes: 12 additions & 5 deletions cmd/nv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import (
"strings"
"syscall"

"github.com/jcouture/env"
"github.com/jcouture/nv/internal/build"
"github.com/jcouture/nv/internal/env"
"github.com/jcouture/nv/internal/parser"
"github.com/mitchellh/go-homedir"
)

Expand Down Expand Up @@ -59,7 +60,7 @@ func main() {
base := make(map[string]string)

for _, filename := range filenames {
override, err := env.Load(filename)
override, err := loadVars(filename)
if err != nil {
fmt.Printf("[Err] %s\n", err)
os.Exit(-1)
Expand All @@ -71,8 +72,9 @@ func main() {
globals := loadGlobals()
base = env.Join(base, globals)

env.Clear()
env.Set(base)
// Clearing everything out the environment... except $PATH (we’re savages)!
env.Clear("PATH")
env.Setvars(base)

binary, lookErr := exec.LookPath(cmd)
if lookErr != nil {
Expand All @@ -95,11 +97,16 @@ func printVersion() {
fmt.Printf("nv version %s\n", build.Version)
}

func loadVars(fn string) (map[string]string, error) {
parser := parser.NewParser(fn)
return parser.Parse()
}

func loadGlobals() map[string]string {
hdir, _ := homedir.Dir()
fn := filepath.Join(hdir, ".nv")
// Purposefuly ignoring any errors
globals, _ := env.Load(fn)
globals, _ := loadVars(fn)

return globals
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/jcouture/nv

go 1.16

require github.com/mitchellh/go-homedir v1.1.0
require (
github.com/jcouture/env v0.1.0
github.com/mitchellh/go-homedir v1.1.0
)
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jcouture/env v0.1.0 h1:BQRXA9TdzFSZZI+95IsrQkeIlpZ/hv/jVl1xjxPMKsE=
github.com/jcouture/env v0.1.0/go.mod h1:/w8O7qcPOryub/LBcp8d2G97vcRN20SkD2LgFcdtJjo=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
56 changes: 0 additions & 56 deletions internal/env/env.go

This file was deleted.

58 changes: 0 additions & 58 deletions internal/env/env_test.go

This file was deleted.

0 comments on commit 90254ef

Please sign in to comment.