feat: documentation for cli

This commit is contained in:
2026-02-07 00:20:57 -05:00
parent 744a2ffd3e
commit b61ca744e0
3 changed files with 12 additions and 5 deletions

2
internal/cli/cli.go Normal file
View File

@@ -0,0 +1,2 @@
// Package cli package provides various utilities to the 'lambda' program.
package cli

View File

@@ -14,6 +14,7 @@ type Destination interface {
// An StdoutDestination writes to stdout. // An StdoutDestination writes to stdout.
type StdoutDestination struct{} type StdoutDestination struct{}
// Write outputs to standard output.
func (d StdoutDestination) Write(data string) error { func (d StdoutDestination) Write(data string) error {
fmt.Println(data) fmt.Println(data)
return nil return nil
@@ -22,6 +23,7 @@ func (d StdoutDestination) Write(data string) error {
// A FileDestination writes to a file. // A FileDestination writes to a file.
type FileDestination struct{ Path string } type FileDestination struct{ Path string }
// Write outputs to a file.
func (d FileDestination) Write(data string) error { func (d FileDestination) Write(data string) error {
return os.WriteFile(d.Path, []byte(data+"\n"), 0644) return os.WriteFile(d.Path, []byte(data+"\n"), 0644)
} }

View File

@@ -5,20 +5,22 @@ import (
"os" "os"
) )
// A method of extracting input from the user. // A Source is a method of extracting input from the user.
type Source interface { type Source interface {
// Fetch data from this source. // Extract fetches data from this source.
Extract() (string, error) Extract() (string, error)
} }
// A source defined by a string. // A StringSource is defined by a string.
type StringSource struct{ Data string } type StringSource struct{ Data string }
// Extract pulls input data from the internal string.
func (s StringSource) Extract() (string, error) { return s.Data, nil } 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{} type StdinSource struct{}
// Extract pulls input data from standard input.
func (s StdinSource) Extract() (string, error) { func (s StdinSource) Extract() (string, error) {
data, err := io.ReadAll(os.Stdin) data, err := io.ReadAll(os.Stdin)
if err != nil { if err != nil {
@@ -28,9 +30,10 @@ func (s StdinSource) Extract() (string, error) {
return string(data), nil return string(data), nil
} }
// A source reading from a file. // A FileSource reads from a file.
type FileSource struct{ Path string } type FileSource struct{ Path string }
// Extract pulls input data from the file source.
func (s FileSource) Extract() (string, error) { func (s FileSource) Extract() (string, error) {
data, err := os.ReadFile(s.Path) data, err := os.ReadFile(s.Path)
if err != nil { if err != nil {