extract config loader
@@ -24,7 +24,7 @@ import (
"os"
"path/filepath"
- "github.com/spf13/afero"
+ "github.com/onflow/flow-cli/pkg/flowkit"
)
// ErrDoesNotExist is error to be returned when config file does not exists
@@ -62,16 +62,15 @@ func (c *ConfigParsers) FindForFormat(extension string) Parser {
// Loader contains actions for composing and modifying configuration.
type Loader struct {
- af *afero.Afero
+ readerWriter flowkit.ReaderWriter
configParsers ConfigParsers
composedFromFile map[string]string
}
// NewLoader returns a new loader.
-func NewLoader(filesystem afero.Fs) *Loader {
- af := &afero.Afero{Fs: filesystem}
+func NewLoader(readerWriter flowkit.ReaderWriter) *Loader {
return &Loader{
- af: af,
+ readerWriter: readerWriter,
composedFromFile: map[string]string{},
}
}
@@ -92,7 +91,7 @@ func (l *Loader) Save(conf *Config, path string) error {
return err
}
- err = l.af.WriteFile(path, data, 0644)
+ err = l.readerWriter.WriteFile(path, data, 0644)
if err != nil {
return err
}
@@ -209,7 +208,7 @@ func (l *Loader) composeConfig(baseConf *Config, conf *Config) {
// simple file loader
func (l *Loader) loadFile(path string) ([]byte, error) {
- raw, err := l.af.ReadFile(path)
+ raw, err := l.readerWriter.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
