style: restructure cli and registry packages #43
2
internal/cli/cli.go
Normal file
2
internal/cli/cli.go
Normal file
@@ -0,0 +1,2 @@
|
||||
// Package cli package provides various utilities to the 'lambda' program.
|
||||
package cli
|
||||
@@ -14,6 +14,7 @@ type Destination interface {
|
||||
// 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
|
||||
@@ -22,6 +23,7 @@ func (d StdoutDestination) Write(data string) error {
|
||||
// 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)
|
||||
}
|
||||
|
||||
@@ -5,20 +5,22 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// A method of extracting input from the user.
|
||||
// A Source is a method of extracting input from the user.
|
||||
type Source interface {
|
||||
// Fetch data from this source.
|
||||
// Extract fetches data from this source.
|
||||
Extract() (string, error)
|
||||
}
|
||||
|
||||
// A source defined by a string.
|
||||
// A StringSource is defined by a string.
|
||||
type StringSource struct{ Data string }
|
||||
|
||||
// Extract pulls input data from the internal string.
|
||||
func (s StringSource) Extract() (string, error) { return s.Data, nil }
|
||||
|
||||
// A source pulling from standard input.
|
||||
// A StdinSource pulls from standard input.
|
||||
type StdinSource struct{}
|
||||
|
||||
// Extract pulls input data from standard input.
|
||||
func (s StdinSource) Extract() (string, error) {
|
||||
data, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
@@ -28,9 +30,10 @@ func (s StdinSource) Extract() (string, error) {
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// A source reading from a file.
|
||||
// A FileSource reads from a file.
|
||||
type FileSource struct{ Path string }
|
||||
|
||||
// Extract pulls input data from the file source.
|
||||
func (s FileSource) Extract() (string, error) {
|
||||
data, err := os.ReadFile(s.Path)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user