Skip to content

Commit

Permalink
Add utility function to parse frizbee configuration from a billy FS
Browse files Browse the repository at this point in the history
This is handy for reading the configuration from a parsed repository.

e.g. as is the case in Minder.
  • Loading branch information
JAORMX committed Dec 15, 2023
1 parent 213f1df commit 241a0bf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"os"
"path/filepath"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -59,9 +61,15 @@ type Filter struct {

// ParseConfigFile parses a configuration file.
func ParseConfigFile(configfile string) (*Config, error) {
bfs := osfs.New(".")
return ParseConfigFileFromFS(bfs, configfile)
}

// ParseConfigFileFromFS parses a configuration file from a filesystem.
func ParseConfigFileFromFS(fs billy.Filesystem, configfile string) (*Config, error) {
cfg := &Config{}
cleancfgfile := filepath.Clean(configfile)
cfgF, err := os.Open(cleancfgfile)
cfgF, err := fs.Open(cleancfgfile)
if err != nil {
if os.IsNotExist(err) {
return cfg, nil
Expand Down

0 comments on commit 241a0bf

Please sign in to comment.