aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugofs/fs.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2017-02-05 10:20:06 +0700
committerBjørn Erik Pedersen <[email protected]>2017-02-17 17:15:26 +0100
commit93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch)
tree5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /hugofs/fs.go
parente34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff)
downloadhugo-93ca7c9e958e34469a337e4efcc7c75774ec50fd.tar.gz
hugo-93ca7c9e958e34469a337e4efcc7c75774ec50fd.zip
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.go25
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)