'wdcli backup': Move to separate package
This commit is contained in:
parent
5cd5ae9be2
commit
822c70cd69
11 changed files with 493 additions and 380 deletions
43
internal/component/backup.go
Normal file
43
internal/component/backup.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package component
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Backupable represents a component with a Backup method
|
||||
type Backupable interface {
|
||||
Component
|
||||
|
||||
// BackupName returns a new name to be used as an argument for path.
|
||||
BackupName() string
|
||||
|
||||
// Backup backs up this component into the destination path path
|
||||
Backup(context BackupContext) error
|
||||
}
|
||||
|
||||
// BackupContext is the context for backups
|
||||
type BackupContext interface {
|
||||
// IO returns the input output stream belonging to this backup file
|
||||
IO() stream.IOStream
|
||||
|
||||
// Name creates a new directory inside the destination.
|
||||
// Passing the empty path creates the destination as a directory.
|
||||
//
|
||||
// It then allows op to fill the file.
|
||||
AddDirectory(path string, op func() error) error
|
||||
|
||||
// CopyFile copies a file from source to dst.
|
||||
CopyFile(dest, src string) error
|
||||
|
||||
// AddFile creates a new file at the provided path inside the destination.
|
||||
// Passing the empty path creates the destination as a file.
|
||||
//
|
||||
// It then allows op to write to the file.
|
||||
//
|
||||
// The op function must not retain file.
|
||||
// The underlying file does not need to be closed.
|
||||
// AddFile will not return before op has returned.
|
||||
AddFile(path string, op func(file io.Writer) error) error
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue