Skip to content

Commit

Permalink
fix(internal): change configuration setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Wabri committed Jun 13, 2024
1 parent 0f6ad4e commit fb4267b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 47 deletions.
36 changes: 36 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package config

import (
"log"
"os"
"path/filepath"

"github.com/Schrodinger-Hat/Daje/constants"

Check failure on line 8 in internal/config/config.go

View workflow job for this annotation

GitHub Actions / lint

import 'github.com/Schrodinger-Hat/Daje/constants' is not allowed from list 'Main' (depguard)
)

func InitEmptyDaje() error {
dajeConfigPath := filepath.Join(constants.DajeConfigBaseDir)

Check failure on line 12 in internal/config/config.go

View workflow job for this annotation

GitHub Actions / lint

badCall: suspicious Join on 1 argument (gocritic)
if err := os.Mkdir(dajeConfigPath, 0755); err != nil {
return err
}

dajeConfigFile := filepath.Join(constants.DajeConfigBaseDir, constants.DajeDotfileName)
if _, err := os.Create(dajeConfigFile); err != nil {
return err
}

return nil
}

func IsDajeInitialized() bool {
dotFile := filepath.Join(constants.DajeConfigBaseDir, constants.DajeDotfileName)
if _, err := os.Stat(dotFile); err != nil {
if os.IsNotExist(err) {
return false
}

log.Fatal(err)
}

return true
}
39 changes: 0 additions & 39 deletions internal/config/config_folder.go

This file was deleted.

17 changes: 9 additions & 8 deletions pkg/cmd/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ func NewCmdInit() *cobra.Command {
}

func submitAction() error {
if config.IsDajeInitialized() {
if !config.IsDajeInitialized() {
err := config.InitEmptyDaje()
if err != nil {
fmt.Println(err)
return nil
}

fmt.Println("Daje has been initialized successfully!")
} else {
fmt.Println("Daje has been already initialized in the system.")
return nil
}

err := config.InitEmptyDaje()
if err != nil {
return nil
}

fmt.Println("Daje has been initialized successfully!")

return nil
}

0 comments on commit fb4267b

Please sign in to comment.