diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-05 10:20:06 +0700 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-17 17:15:26 +0100 |
commit | 93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch) | |
tree | 5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /hugofs/fs.go | |
parent | e34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff) |
all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables
the use if `t.Parallel` in tests.
Updates #2701
Fixes #3016
Diffstat (limited to 'hugofs/fs.go')
-rw-r--r-- | hugofs/fs.go | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/hugofs/fs.go b/hugofs/fs.go index 3afa17956..1ddb98214 100644 --- a/hugofs/fs.go +++ b/hugofs/fs.go @@ -16,7 +16,7 @@ package hugofs import ( "github.com/spf13/afero" - "github.com/spf13/viper" + "github.com/spf13/hugo/config" ) // Os points to an Os Afero file system. @@ -39,30 +39,37 @@ type Fs struct { // NewDefault creates a new Fs with the OS file system // as source and destination file systems. -func NewDefault() *Fs { +func NewDefault(cfg config.Provider) *Fs { fs := &afero.OsFs{} - return newFs(fs) + return newFs(fs, cfg) } // NewDefault creates a new Fs with the MemMapFs // as source and destination file systems. // Useful for testing. -func NewMem() *Fs { +func NewMem(cfg config.Provider) *Fs { fs := &afero.MemMapFs{} - return newFs(fs) + return newFs(fs, cfg) } -func newFs(base afero.Fs) *Fs { +// NewFrom creates a new Fs based on the provided Afero Fs +// as source and destination file systems. +// Useful for testing. +func NewFrom(fs afero.Fs, cfg config.Provider) *Fs { + return newFs(fs, cfg) +} + +func newFs(base afero.Fs, cfg config.Provider) *Fs { return &Fs{ Source: base, Destination: base, Os: &afero.OsFs{}, - WorkingDir: getWorkingDirFs(base), + WorkingDir: getWorkingDirFs(base, cfg), } } -func getWorkingDirFs(base afero.Fs) *afero.BasePathFs { - workingDir := viper.GetString("workingDir") +func getWorkingDirFs(base afero.Fs, cfg config.Provider) *afero.BasePathFs { + workingDir := cfg.GetString("workingDir") if workingDir != "" { return afero.NewBasePathFs(afero.NewReadOnlyFs(base), workingDir).(*afero.BasePathFs) |