Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
Oliver Davies 2025-09-30 23:49:23 +01:00
parent a4901b9ae7
commit d27eca0a07
13 changed files with 71 additions and 57 deletions

39
internal/file/main.go Normal file
View file

@ -0,0 +1,39 @@
package file
import (
"fmt"
"os"
"code.oliverdavies.uk/opdavies/cmd-zet/internal/lib"
)
func EditFile(filePath 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)
}
editor := os.Getenv("EDITOR")
err := lib.Exec(editor, filePath)
if err != nil {
fmt.Println(err)
}
}
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)
}