Skip to content

Commit

Permalink
Merge pull request #96 from cloudsynth/add_env
Browse files Browse the repository at this point in the history
Add envfile support
  • Loading branch information
pnegahdar authored Aug 24, 2020
2 parents 06be1e8 + f849af7 commit 9801a53
Show file tree
Hide file tree
Showing 426 changed files with 154 additions and 178,681 deletions.
10 changes: 5 additions & 5 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/fatih/color"
"github.com/pnegahdar/venvy/manager"
"github.com/pnegahdar/venvy/modules"
"github.com/pnegahdar/venvy/util"
"github.com/pnegahdar/venvy/manager"
logger "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"io/ioutil"
Expand All @@ -15,7 +16,6 @@ import (
"os/signal"
"strings"
"syscall"
"github.com/fatih/color"
)

var activateFileEnvVar = fmt.Sprintf("%s_ACTIVATE_FILE", strings.ToUpper(venvy.ProjectName))
Expand Down Expand Up @@ -223,7 +223,7 @@ func isCIEnv() bool {
func LoadConfigCommands() ([]*cobra.Command, error) {
cmds := []*cobra.Command{}
useHistory := true
if isCIEnv(){
if isCIEnv() {
logger.Debug("Not using config history, CI environment detected.")
}
if os.Getenv(disableHistoryEnvVar) != "" {
Expand Down Expand Up @@ -322,10 +322,10 @@ func main() {

// Set debug early on so
for _, arg := range os.Args {
if arg == "-v" || arg == "--verbose"{
if arg == "-v" || arg == "--verbose" {
logger.SetLevel(logger.DebugLevel)
}
if arg == "--"{
if arg == "--" {
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"
"github.com/mitchellh/go-homedir"
"github.com/pnegahdar/venvy/util"
"github.com/pnegahdar/venvy/manager"
"github.com/pnegahdar/venvy/util"
logger "github.com/sirupsen/logrus"
"io/ioutil"
"os"
Expand Down
22 changes: 14 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
module github.com/pnegahdar/venvy

go 1.14

require (
github.com/BurntSushi/toml v0.3.0
github.com/fatih/color v1.6.0
github.com/go-playground/locales v0.11.2
github.com/go-playground/universal-translator v0.16.0
github.com/go-playground/locales v0.11.2 // indirect
github.com/go-playground/universal-translator v0.16.0 // indirect
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c // indirect
github.com/inconshreveable/mousetrap v1.0.0
github.com/mattn/go-colorable v0.0.9
github.com/mattn/go-isatty v0.0.3
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747
github.com/onsi/ginkgo v1.14.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible
github.com/sirupsen/logrus v1.0.4
github.com/spf13/cobra v0.0.1
github.com/spf13/pflag v1.0.0
golang.org/x/crypto v0.0.0-20180228161326-91a49db82a88
golang.org/x/sys v0.0.0-20180302081741-dd2ff4accc09
github.com/spf13/pflag v1.0.0 // indirect
github.com/stretchr/testify v1.6.1 // indirect
github.com/subosito/gotenv v1.2.0
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.11.0
)
82 changes: 78 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,31 +1,105 @@
github.com/BurntSushi/toml v0.3.0 h1:e1/Ivsx3Z0FVTV0NSOv/aVgbUWyQuzj7DDnFblkRvsY=
github.com/BurntSushi/toml v0.3.0/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.6.0 h1:66qjqZk8kalYAvDRtM1AdAJQI0tj4Wrue3Eq3B3pmFU=
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-playground/locales v0.11.2 h1:wH6Ksuvzk0SU9M6wUeGz/EaRWnavAHCOsFre1njzgi8=
github.com/go-playground/locales v0.11.2/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM=
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747 h1:eQox4Rh4ewJF+mqYPxCkmBAirRnPaHEB26UkNuPyjlk=
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
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/sirupsen/logrus v1.0.4 h1:gzbtLsZC3Ic5PptoRG+kQj4L60qjK7H7XszrU163JNQ=
github.com/sirupsen/logrus v1.0.4/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/spf13/cobra v0.0.1 h1:zZh3X5aZbdnoj+4XkaBxKfhO4ot82icYdhhREIAXIj8=
github.com/spf13/cobra v0.0.1/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.0 h1:oaPbdDe/x0UncahuwiPxW1GYJyilRAdsPnq3e1yaPcI=
github.com/spf13/pflag v1.0.0/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
golang.org/x/crypto v0.0.0-20180228161326-91a49db82a88 h1:jLkAo/qlT9whgCLYC5GAJ9kcKrv3Wj8VCc4N+KJ4wpw=
golang.org/x/crypto v0.0.0-20180228161326-91a49db82a88/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20180302081741-dd2ff4accc09 h1:wNPZbZUOH0tyqngVRXeF2iQm19+ssqyebJTCFBvxsow=
golang.org/x/sys v0.0.0-20180302081741-dd2ff4accc09/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 h1:AeiKBIuRw3UomYXSbLy0Mc2dDLfdtbT/IVn4keq83P0=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNjB2u4i700xBkIT4e0=
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v9 v9.11.0 h1:ER548TqE6ZknRRDDo0/tP8I12UHYxNlIfss8tMd4iCo=
gopkg.in/go-playground/validator.v9 v9.11.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
10 changes: 9 additions & 1 deletion manager/project_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func (pm *ProjectManager) RootPath(elem ...string) string {
return filepath.Join(elem...)
}

func (pm *ProjectManager) ResolveRootPath(path string) string {
fullPath := util.MustExpandPath(path)
if !filepath.IsAbs(path) {
fullPath = pm.RootPath(path)
}
return fullPath
}

func (pm *ProjectManager) AppendModules(modules ...*Module) {
for _, module := range modules {
pm.relatedModules[module.Name] = module
Expand All @@ -76,7 +84,7 @@ func (pm *ProjectManager) AppendModules(modules ...*Module) {

func (pm *ProjectManager) PrependModules(modules ...*Module) {
// prepend in reverse so left most arg is up front
for i := len(modules) - 1; i >= 0; i -- {
for i := len(modules) - 1; i >= 0; i-- {
pm.relatedModules[modules[i].Name] = modules[i]
pm.Project.Modules = append([]string{modules[i].Name}, pm.Project.Modules...)

Expand Down
2 changes: 1 addition & 1 deletion manager/venvy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const ProjectName = "venvy"
const Version = "0.0.1"
const Version = "0.0.2"

type Module struct {
Name string `validate:"cleanName"`
Expand Down
26 changes: 22 additions & 4 deletions modules/envvar.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
package modules

import (
"bytes"
"fmt"
"github.com/pnegahdar/venvy/util"
"github.com/pnegahdar/venvy/manager"
"github.com/pnegahdar/venvy/util"
"github.com/subosito/gotenv"
"io/ioutil"
"os"
)

type EnvVarConfig struct {
Vars map[string]string
UnsetVars []string `json:"unset_vars"`
Vars map[string]string `json:"vars"`
Files []string `json:"files"`
UnsetVars []string `json:"unset_vars"`
}

type EnvvarModule struct {
config *EnvVarConfig
manager *venvy.ProjectManager
}

func (ev *EnvvarModule) ShellActivateCommands() ([]string, error) {
commands := []string{}

for _, file := range ev.config.Files {
fullPath := ev.manager.ResolveRootPath(file)
data, err := ioutil.ReadFile(fullPath)
if err != nil {
return nil, fmt.Errorf("unable to find file %s at %s", file, fullPath)
}
pairs := gotenv.Parse(bytes.NewReader(data))
for key, value := range pairs {
commands = append(commands, fmt.Sprintf(`export %s="%s"`, key, value))
}
}

for key, value := range ev.config.Vars {
commands = append(commands, fmt.Sprintf(`export %s="%s"`, key, value))
}
Expand Down Expand Up @@ -55,5 +73,5 @@ func NewEnvVarModule(manager *venvy.ProjectManager, self *venvy.Module) (venvy.M
if err != nil {
return nil, err
}
return &EnvvarModule{config: moduleConfig}, nil
return &EnvvarModule{config: moduleConfig, manager: manager}, nil
}
2 changes: 1 addition & 1 deletion modules/exec.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package modules

import (
"github.com/pnegahdar/venvy/util"
"github.com/pnegahdar/venvy/manager"
"github.com/pnegahdar/venvy/util"
)

type ExecConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion modules/jump.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package modules

import (
"fmt"
"github.com/pnegahdar/venvy/util"
"github.com/pnegahdar/venvy/manager"
"github.com/pnegahdar/venvy/util"
"os"
)

Expand Down
10 changes: 5 additions & 5 deletions modules/ps1.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

type PS1Config struct {
Value string
ZshValue string
Value string
ZshValue string
BashValue string
}

Expand All @@ -24,7 +24,7 @@ const escape = "\x1b"
const noPrintStart = "__noprintstart__"
const noPrintEnd = "__noprintend__"

func replaceNoPrint(data, startSeq, endSeq string) string{
func replaceNoPrint(data, startSeq, endSeq string) string {
replaceStart := strings.ReplaceAll(data, noPrintStart, startSeq)
return strings.ReplaceAll(replaceStart, noPrintEnd, endSeq)

Expand Down Expand Up @@ -86,10 +86,10 @@ func NewPS1Module(manager *venvy.ProjectManager, self *venvy.Module) (venvy.Modu
moduleConfig.BashValue = replaceNoPrint(colored, "\\[", "\\]")
moduleConfig.ZshValue = replaceNoPrint(colored, "%{", "%}")
}
if moduleConfig.BashValue == ""{
if moduleConfig.BashValue == "" {
moduleConfig.BashValue = moduleConfig.Value
}
if moduleConfig.ZshValue == ""{
if moduleConfig.ZshValue == "" {
moduleConfig.ZshValue = moduleConfig.Value
}
return &PS1Module{manager: manager, config: moduleConfig}, nil
Expand Down
18 changes: 5 additions & 13 deletions modules/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package modules
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/pnegahdar/venvy/util"
"github.com/pnegahdar/venvy/manager"
"github.com/pnegahdar/venvy/util"
"io/ioutil"
"strings"
"path/filepath"
"encoding/json"
"strings"
)

const DefaultPython = "python3.6"
Expand Down Expand Up @@ -56,14 +56,6 @@ func (pm *PythonModule) autoInstallLastHash() string {
return strings.TrimSpace(string(data))
}

func (pm *PythonModule) resolvePath(path string) string {
fullPath := util.MustExpandPath(path)
if !filepath.IsAbs(path) {
fullPath = pm.manager.RootPath(path)
}
return fullPath
}

func (pm *PythonModule) autoInstallCalculateDepHash() (string, error) {
if len(pm.config.Dependencies) == 0 {
return "", nil
Expand All @@ -86,15 +78,15 @@ func (pm *PythonModule) autoInstallCalculateDepHash() (string, error) {
for _, dep := range pm.config.Dependencies {
// read the deps if its a file, preferring .txt instead of isFile type check for safety sake
if strings.HasSuffix(dep, ".txt") {
fullPath := pm.resolvePath(dep)
fullPath := pm.manager.ResolveRootPath(dep)
err = writeFileHash(fullPath)
if err != nil {
return "", err
}
}
}
for _, additionalFile := range pm.config.AdditionalTrackFiles {
fullPath := pm.resolvePath(additionalFile)
fullPath := pm.manager.ResolveRootPath(additionalFile)
err = writeFileHash(fullPath)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion modules/tmux_window.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package modules

import (
"github.com/pnegahdar/venvy/util"
"github.com/pnegahdar/venvy/manager"
"github.com/pnegahdar/venvy/util"
logger "github.com/sirupsen/logrus"
"os/exec"

Expand Down
Loading

0 comments on commit 9801a53

Please sign in to comment.