Refactor
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
665ef94ca9
commit
a3202aaff3
17 changed files with 63 additions and 56 deletions
|
@ -1,39 +0,0 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"code.oliverdavies.uk/opdavies/cmd-zet/internal/lib"
|
||||
)
|
||||
|
||||
func Edit(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 View(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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue