Documentation ¶
Index ¶
- Variables
- type DirFSGenerator
- type Directory
- type FSGenerator
- type File
- type IsNewFile
- type Template
- type WritableFS
- type WritableFile
- type WritableMapFS
- func (fsys WritableMapFS) CreateTemp(dir string, pattern string) (WritableFile, error)
- func (fsys WritableMapFS) Glob(pattern string) ([]string, error)
- func (fsys WritableMapFS) Mkdir(name string, perm fs.FileMode) error
- func (fsys WritableMapFS) Open(name string) (fs.File, error)
- func (fsys WritableMapFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (fsys WritableMapFS) ReadFile(name string) ([]byte, error)
- func (fsys WritableMapFS) Remove(path string) error
- func (fsys WritableMapFS) RemoveAll(dir string) error
- func (fsys WritableMapFS) Rename(oldpath string, newpath string) error
- func (fsys WritableMapFS) Stat(name string) (fs.FileInfo, error)
- func (fsys WritableMapFS) Sub(dir string) (fs.FS, error)
- type WriterToFile
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCleaningOutputDir = errors.New("error cleaning output dir")
View Source
var ErrMissingFS = errors.New("missing FS")
Functions ¶
This section is empty.
Types ¶
type DirFSGenerator ¶
type FSGenerator ¶
type FSGenerator struct { FS WritableFS ErrorOnExistingDir bool CleanDir bool ErrorOnExistingFile bool // contains filtered or unexported fields }
func (*FSGenerator) Generate ¶
func (g *FSGenerator) Generate(ctx context.Context, files ...File) error
Example ¶
outpath := path.Join(os.TempDir(), "out") outfs, err := MkWritableDirFS(outpath) if err != nil { panic(err) } g := &FSGenerator{ FS: outfs, } err = g.Generate( context.Background(), PlainFile("README.md", "# drydock"), Dir("bin", Dir("cli", PlainFile("main.go", "package main"), ), ), Dir("pkg", PlainFile("README.md", "how to use this thing"), Dir("cli", PlainFile("cli.go", "package cli..."), PlainFile("run.go", "package cli...run..."), ), ), ) if err != nil { panic(err) } entries, err := os.ReadDir(outpath) if err != nil { panic(err) } for _, e := range entries { fmt.Println(e) }
Output: - README.md d bin/ d pkg/
type WritableFS ¶
type WritableFS interface { fs.ReadFileFS // Mkdir should behave like [os.Mkdir]. Mkdir(name string, perm fs.FileMode) error // Rename should behave like [os.Rename]. Returned errors will also be [os.LinkError]. Rename(oldpath string, newpath string) error // Remove should behave like [os.Remove]. Remove(path string) error // RemoveAll should behave like [os.RemoveAll]. RemoveAll(path string) error // CreateTemp should behave like [os.CreateTemp]. CreateTemp(dir string, pattern string) (WritableFile, error) }
WritableFS extends the standard io/fs.FS interface with writing capabilities for hierarchical file systems.
func MkWritableDirFS ¶
func MkWritableDirFS(dir string) (WritableFS, error)
MkWritableDirFS is like NewWritableDirFS but will create the directory if it doesn't exist.
func NewWritableDirFS ¶
func NewWritableDirFS(dir string) WritableFS
NewWritableDirFS creates a new [WritablesFS] backed by the real filesystem, like os.DirFS.
type WritableMapFS ¶
WritableMapFS extends testing/fstest.MapFS with WritableFS capabilities.
func (WritableMapFS) CreateTemp ¶
func (fsys WritableMapFS) CreateTemp(dir string, pattern string) (WritableFile, error)
CreateTemp does not implement the pattern function of os.CreateTemp. The default temp dir is `/tmp`.
func (WritableMapFS) ReadDir ¶
func (fsys WritableMapFS) ReadDir(name string) ([]fs.DirEntry, error)
func (WritableMapFS) Remove ¶
func (fsys WritableMapFS) Remove(path string) error
func (WritableMapFS) RemoveAll ¶
func (fsys WritableMapFS) RemoveAll(dir string) error
type WriterToFile ¶
Click to show internal directories.
Click to hide internal directories.