commit 64dea033da4aa63f3f445825ffb1d6fae03aa6b7
parent 4e95bbe3a52dfd56f3be904fa9b85cf4051d409f
Author: Tyler Clark <tyler.clark@foxide.xyz>
Date: Fri, 9 Jan 2026 15:54:38 -0500
Re-implementing file conversion and removing unnecessary function.
This patch adds back the document conversion capability to the program as well
as removing the now unnecessary 'CopyFile' function and the 'io' import, as the
conversion function will now use pandoc for doing that and converting files all
at once.
Diffstat:
| M | main.go | | | 41 | +++++------------------------------------ |
1 file changed, 5 insertions(+), 36 deletions(-)
diff --git a/main.go b/main.go
@@ -19,7 +19,6 @@ package main
import (
"fmt" // For formatting some outputs
- "io" // Used for copying individual files
"os" // File system and arguments
"os/exec" // For running OS operations
"path" // For removing file extensions
@@ -28,34 +27,9 @@ import (
/* Version Number */
const version = "0.0.1: Shoddy"
-func copyFile(source, dest string) error {
- sourceFile, err := os.Open(source)
- if err != nil {
- return err
- }
- defer sourceFile.Close()
-
- destFile, err := os.Create(dest)
- if err != nil {
- return err
- }
- defer destFile.Close()
-
- _, err = io.Copy(destFile, sourceFile)
- if err == nil {
- sourceInfo, err := os.Stat(source)
- if err != nil {
- err = os.Chmod(dest, sourceInfo.Mode())
- }
- }
- return err
-}
-
/* This is a test function to try to copy a directory */
func DirSetup(source string, destination string) error {
- /* Validate its existence */
- //ValidateDir(source)
srcInfo, err := os.Stat(source)
if os.IsNotExist(err) {
@@ -79,7 +53,6 @@ func DirSetup(source string, destination string) error {
/* Based around solution presented here: */
/* https://gistlib.com/go/copy-a-directory-in-go */
- /* Might change, as I am not sure how much I love that one */
for _, entry := range entries {
srcPath := source + "/" + entry.Name()
dstPath := destination + "/" + entry.Name()
@@ -90,17 +63,13 @@ func DirSetup(source string, destination string) error {
return err
}
} else {
- err = copyFile(srcPath, dstPath)
+ err = ConvertFile(source, entry.Name(), destination)
if err != nil {
return err
}
}
}
- //fsys := os.DirFS(source)
- //os.CopyFS(destination, fsys)
- //fmt.Printf("Directory: %v copied\n", source)
-
return nil
}
@@ -108,16 +77,17 @@ func RemoveExt(filename string) string {
return filename[:len(filename)-len(path.Ext(filename))]
}
-func ConvertFile(filename string) {
+func ConvertFile(filepath, filename, destination string) error {
fmt.Println("Converting following file to HTML:", filename)
oFile := RemoveExt(filename)
- cmd := exec.Command("pandoc", filename, "-o", oFile + ".html")
+ cmd := exec.Command("pandoc", filepath + "/" + filename, "-o", destination + "/" + oFile + ".html")
output, err := cmd.Output()
if err != nil {
fmt.Println("Error:", err)
- return
+ return err
}
fmt.Println(string(output))
+ return nil
}
func CallHelp() {
@@ -149,7 +119,6 @@ func ArgParser (argument[] string) {
}
DirSetup(argument[i], argument[i + 1])
i++
- //ValidateFile(argument[i])
}
}
}