Adding ways to create new files

This commit is contained in:
Alex Yatskov 2015-11-02 18:52:05 +09:00
parent c1723c902d
commit b5470ba396
2 changed files with 28 additions and 5 deletions

View File

@ -24,6 +24,7 @@ package goldsmith
import ( import (
"bytes" "bytes"
"fmt"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -69,11 +70,7 @@ func (gs *goldsmith) scan() {
panic(err) panic(err)
} }
file := &File{ file, _ := gs.NewFile(relPath)
Path: relPath,
Meta: make(map[string]interface{}),
Buff: new(bytes.Buffer),
}
var f *os.File var f *os.File
if f, file.Err = os.Open(match); file.Err == nil { if f, file.Err = os.Open(match); file.Err == nil {
@ -178,6 +175,29 @@ func (gs *goldsmith) chainMultiple(s stage, cm ChainerMultiple, globs []string)
} }
} }
func (gs *goldsmith) NewFile(path string) (*File, error) {
if filepath.IsAbs(path) {
return nil, fmt.Errorf("absolute paths are not supported: %s", path)
}
file := &File{
Path: path,
Meta: make(map[string]interface{}),
Buff: new(bytes.Buffer),
}
return file, nil
}
func (gs *goldsmith) RefFile(path string) error {
if filepath.IsAbs(path) {
return fmt.Errorf("absolute paths are not supported: %s", path)
}
gs.refs[path] = true
return nil
}
func (gs *goldsmith) SrcDir() string { func (gs *goldsmith) SrcDir() string {
return gs.srcDir return gs.srcDir
} }

View File

@ -45,6 +45,9 @@ type File struct {
} }
type Context interface { type Context interface {
NewFile(path string) (*File, error)
RefFile(path string) error
SrcDir() string SrcDir() string
DstDir() string DstDir() string
} }