30 lines
609 B
Go
30 lines
609 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// A Destination is method of writing output to the user.
|
|
type Destination interface {
|
|
// Write data to this destination.
|
|
Write(data string) error
|
|
}
|
|
|
|
// An StdoutDestination writes to stdout.
|
|
type StdoutDestination struct{}
|
|
|
|
// Write outputs to standard output.
|
|
func (d StdoutDestination) Write(data string) error {
|
|
fmt.Println(data)
|
|
return nil
|
|
}
|
|
|
|
// A FileDestination writes to a file.
|
|
type FileDestination struct{ Path string }
|
|
|
|
// Write outputs to a file.
|
|
func (d FileDestination) Write(data string) error {
|
|
return os.WriteFile(d.Path, []byte(data+"\n"), 0644)
|
|
}
|