Add view command

Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
Oliver Davies 2025-09-24 08:30:00 +01:00
parent f9a05ab5d9
commit 0a6e2b075c
4 changed files with 68 additions and 5 deletions

22
internal/lib/file.go Normal file
View file

@ -0,0 +1,22 @@
package lib
import (
"fmt"
"os"
)
func ViewFile(filePath string) string {
if _, err := os.Stat(filePath); os.IsNotExist(err) {
fmt.Printf("Error: The file for path '%s' was not found\n", filePath)
os.Exit(1)
}
content, err := os.ReadFile(filePath)
if err != nil {
fmt.Println("Error opening the file:", err)
os.Exit(1)
}
return string(content)
}