Skip to content

Commit

Permalink
direnv intigration
Browse files Browse the repository at this point in the history
Signed-off-by: Horiodino <[email protected]>
  • Loading branch information
Horiodino committed Jun 7, 2024
1 parent fd63f5d commit 59c20b2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func GetBSFInitializers() (bsfv1.SearchServiceClient, *hcl2nix.FileHandlers, err
}

// CleanUp removes the bsf config if any error occurs in init process (ctrl+c or any init process stage)
func cleanUp(){
configs := []string{"bsf", "bsf.hcl", "bsf.lock"}
func cleanUp() {
configs := []string{"bsf", "bsf.hcl", "bsf.lock", ".envrc"}

for _, f := range configs {
os.RemoveAll(f)
Expand Down
2 changes: 1 addition & 1 deletion cmd/init/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
err = m.processStages(m.stage)
if err != nil {
cleanUp()
cleanUp()
return m, tea.Quit
}
m.stage++
Expand Down
27 changes: 26 additions & 1 deletion cmd/precheck/precheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,32 @@ func IsFlakesEnabled() {
}
}

// generates .envrc for Direnv intigration
func generateEnvrc() error {
file, err := os.Create(".envrc")
if err != nil {
fmt.Println(styles.ErrorStyle.Render("", err.Error()))
os.Exit(1)
}

defer file.Close()

_, err = file.WriteString("use flake bsf/.")
if err != nil {
fmt.Println(styles.ErrorStyle.Render("", err.Error()))
os.Exit(1)
}

fmt.Println(styles.HelpStyle.Render(" ✅ .envrc generated"))

return nil
}

// AllPrechecks runs all the prechecks
func AllPrechecks() {
fmt.Println(styles.TextStyle.Render("Running prechecks..."))
var wg sync.WaitGroup
wg.Add(3)
wg.Add(4)
go func() {
ValidateNixVersion()
wg.Done()
Expand All @@ -85,6 +106,10 @@ func AllPrechecks() {
wg.Done()

}()
go func() {
generateEnvrc()
wg.Done()
}()
go func() {
wg.Done()

Expand Down

0 comments on commit 59c20b2

Please sign in to comment.