37 lines
649 B
Go
37 lines
649 B
Go
package lib
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
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 := 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)
|
|
}
|