Add view
command
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
f9a05ab5d9
commit
0a6e2b075c
4 changed files with 68 additions and 5 deletions
22
internal/lib/file.go
Normal file
22
internal/lib/file.go
Normal 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)
|
||||
}
|
|
@ -60,6 +60,12 @@ func ParseZetList(ids []int) []string {
|
|||
return lines
|
||||
}
|
||||
|
||||
func ViewZet(zetDir string, id int) string {
|
||||
zetPath := path.Join(zetDir, strconv.Itoa(id), "index.adoc")
|
||||
|
||||
return ViewFile(zetPath)
|
||||
}
|
||||
|
||||
func getTitle(id int) string {
|
||||
return getTitleFromFile(path.Join(strconv.Itoa(id), "index.adoc"))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue