feat: documentation for cli
This commit is contained in:
@@ -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