Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
(maint) Break out utilsHelper to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
da-ar committed Aug 13, 2021
1 parent 293d15d commit a6eea92
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
File renamed without changes.
29 changes: 0 additions & 29 deletions internal/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package utils
import (
"fmt"
"io"
"os"
"path/filepath"
)

// contains checks if a string is present in a slice
Expand Down Expand Up @@ -48,30 +46,3 @@ func ChunkedCopy(dst io.Writer, src io.Reader) error {
}
}
}

type UtilsHelperI interface {
IsModuleRoot() (string, error)
Dir() (string, error)
}

type UtilsHelper struct{}

// Check if we're currently in the module root dir.
// Return the sanitized file path if we are in a module root, otherwise an empty string.
func (u *UtilsHelper) IsModuleRoot() (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}

_, err = os.Stat(filepath.Join(wd, "metadata.json"))
if err != nil {
return "", err
}

return filepath.Clean(wd), nil
}

func (u *UtilsHelper) Dir() (string, error) {
return homedir.Dir()
}
35 changes: 35 additions & 0 deletions internal/pkg/utils/utilsHelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package utils

import (
"os"
"path/filepath"

"github.com/mitchellh/go-homedir"
)

type UtilsHelperI interface {
IsModuleRoot() (string, error)
Dir() (string, error)
}

type UtilsHelper struct{}

// Check if we're currently in the module root dir.
// Return the sanitized file path if we are in a module root, otherwise an empty string.
func (u *UtilsHelper) IsModuleRoot() (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}

_, err = os.Stat(filepath.Join(wd, "metadata.json"))
if err != nil {
return "", err
}

return filepath.Clean(wd), nil
}

func (u *UtilsHelper) Dir() (string, error) {
return homedir.Dir()
}

0 comments on commit a6eea92

Please sign in to comment.