From b61ca744e01d74c4fd185e5c1232e04f4840be16 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Sat, 7 Feb 2026 00:20:57 -0500 Subject: [PATCH] feat: documentation for cli --- internal/cli/cli.go | 2 ++ internal/cli/destination.go | 2 ++ internal/cli/source.go | 13 ++++++++----- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 internal/cli/cli.go diff --git a/internal/cli/cli.go b/internal/cli/cli.go new file mode 100644 index 0000000..a1ec311 --- /dev/null +++ b/internal/cli/cli.go @@ -0,0 +1,2 @@ +// Package cli package provides various utilities to the 'lambda' program. +package cli diff --git a/internal/cli/destination.go b/internal/cli/destination.go index 194dbeb..4917a12 100644 --- a/internal/cli/destination.go +++ b/internal/cli/destination.go @@ -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) } diff --git a/internal/cli/source.go b/internal/cli/source.go index 0850258..70f72b0 100644 --- a/internal/cli/source.go +++ b/internal/cli/source.go @@ -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 {