Author: LakeFox
Email: [email protected]
Date: Sun, 20 Apr 2025 21:12:40 -0600
main.go
Re made the entire thing
Commits
Diff
diff --git a/main.go b/main.go
index cfaed4c..490e27c 100644
--- a/main.go
+++ b/main.go
@@ -7 +6,0 @@ import (
-	"logc/email"
@@ -10 +8,0 @@ import (
-	"logc/dir"
@@ -20,0 +19,3 @@ import (
+// !NOTE: Contact the author at [email protected]
+
+// ?qaz.sh???
@@ -34,2 +35,2 @@ func main() {
-	username := flag.String("username", "", "Email login username")
-	password := flag.String("password", "", "Email login password")
+	// username := flag.String("username", "", "Email login username")
+	// password := flag.String("password", "", "Email login password")
@@ -43 +44,2 @@ func main() {
-	flag.Var(&replaces, "replace", `RegExp to replace text within a field. Example: --replace commit.email=/(\w)(\w*)(\w)@([^\s]+)/${1}*${3}@${4}/ (censors emails it git commits) Optional: Import a replace file with a .rf extention Example: --replace commit.email=/path/to/email/regex.rf`)
+	flag.Var(&replaces, "replace", `RegExp to replace text within a field. Example: --replace commit.email=/(\w)(\w*)(\w)@([^\s]+)/${1}*${3}@${4}/ (censors emails it git commits)`)
+	replaceFile := flag.String("replaceFile", "", "File containing replace statements")
@@ -48 +50 @@ func main() {
-	cwd := flag.String("dir", ".", "Set the current directory")
+	outputDir := flag.String("dir", ".", "Directory to write the output file to")
@@ -55,2 +57,5 @@ func main() {
-	op := filepath.Join(*cwd, *outputPath)
-	enc := strings.ToLower(*encoding)
+	// Validate the root directory
+	if _, err := os.Stat(*path); os.IsNotExist(err) {
+		fmt.Println("Directory does not exist:", path)
+		os.Exit(1)
+	}
@@ -58,5 +63,11 @@ func main() {
-	var tmpl *template.Template
-	var err error
-	if enc != "json" && enc != "text" && enc != "xml" {
-		templatePath := filepath.Join(*cwd, enc)
-		tmpl, err = template.ParseFiles(templatePath)
+	// add checks for errors
+	data := []interface{}{}
+	if *mode == "tagc" {
+		r, err := tagc.Read(*path)
+		if err != nil {
+			panic(err)
+		}
+
+		for _, v := range r {
+			data = append(data, v)
+		}
@@ -63,0 +75,2 @@ func main() {
+	} else if *mode == "git" {
+		r, err := git.Read(*path)
@@ -66,0 +80,4 @@ func main() {
+
+		for _, v := range r {
+			data = append(data, v)
+		}
@@ -69,3 +86 @@ func main() {
-	// !TODO: Make async so you don't need to store soo much in memory
-	// add checks for errors
-	
+	results := search.All(data, filters.Array(), removes.Array(), replaces.Array(), *replaceFile)
@@ -73,2 +88,2 @@ func main() {
-	handle := (func (data interface{}) {
-		result := search.One(data, filters.Array(), removes.Array(), replaces.Array(), *cwd)
+	op := filepath.Join(*outputDir, *outputPath)
+	enc := strings.ToLower(*encoding)
@@ -76 +91,8 @@ func main() {
-		var out string
+	var tmpl *template.Template
+	if enc != "json" || enc != "text" || enc != "xml" {
+		templatePath := filepath.Join(*path, enc)
+		tmpl, _ = template.ParseFiles(templatePath)
+	}
+
+	for _, v := range results {
+		var data string
@@ -78 +100 @@ func main() {
-			out = output.JSON(result)
+			data = output.JSON(v)
@@ -80 +102 @@ func main() {
-			out = output.Text(result)
+			data = output.Text(v)
@@ -82 +104 @@ func main() {
-			out = output.XML(result)
+			data = output.XML(results)
@@ -85 +107 @@ func main() {
-			err := tmpl.Execute(&f, result)
+			err := tmpl.Execute(&f, v)
@@ -87 +108,0 @@ func main() {
-				fmt.Println("Template path not found: ", filepath.Join(*cwd, enc))
@@ -90 +111 @@ func main() {
-			out = f.String()
+			data = f.String()
@@ -94 +115 @@ func main() {
-			fmt.Println(out)
+			fmt.Println(data)
@@ -96 +117 @@ func main() {
-			p := output.FormatPath(op, result)
+			p := output.FormatPath(op, v)
@@ -100 +121,2 @@ func main() {
-			err := os.WriteFile(p, []byte(out), 0666)
+			fmt.Println(p)
+			err := os.WriteFile(p, []byte(data), 0666)
@@ -105,32 +127 @@ func main() {
-})
-
-
-
-	if *mode == "tagc" {
-		err := tagc.Read(*path, handle)
-		if err != nil {
-			panic(err)
-		}
-
-
-	} else if *mode == "git" {
-		err := git.Read(*path, handle)
-		if err != nil {
-			panic(err)
-		}
-
-	} else if *mode == "email" {
-		inbox := email.Connect(*path, *username, *password)
-		inbox.GetMessages("INBOX")
-
-		for _, v := range inbox.Threads {
-			handle(v)
-		}
-		
-		inbox.Client.Logout()
-	} else if *mode == "directory" {
-		err := dir.Read(*path, handle)
-		if err != nil {
-			panic(err)
-		}
-	} 
+	}
@@ -138 +128,0 @@ func main() {
-	
@@ -140 +130 @@ func main() {
-		fs := http.FileServer(http.Dir(*cwd))
+		fs := http.FileServer(http.Dir(*outputDir))
@@ -144 +134 @@ func main() {
-		fmt.Println("Serving: " + *cwd)
+		fmt.Println("Serving: " + *path)
package main

import (
	"bytes"
	"flag"
	"fmt"
	"logc/email"
	"logc/flagtype"
	"logc/git"
	"logc/dir"
	"logc/output"
	"logc/search"
	"logc/tagc"
	"net/http"
	"os"
	"path/filepath"
	"strings"
	"text/template"
)

// !NOTE: The idea is source -> filter -> encode -> output
// + ./ (directory) -> only include issues -> parse the comments -> output text to the console
// + .git -> get the first five commits -> parse the git repo -> output as html and save the files as user/commitid/filepath
// + take all the files in a directory -> no filter -> add a template -> save as dirname.html
// + take directory and output as html folder structure or json or template

// !FUTURE: Add things like spreadsheets, rss, and databases (ip connections too) (try to replace retool) also email output
// + add sorting

func main() {

	// -src mail.privateemail.com:993 -username [email protected] -password 123qweASD
	path := flag.String("src", ".", "Source directory or file")
	username := flag.String("username", "", "Email login username")
	password := flag.String("password", "", "Email login password")
	mode := flag.String("mode", "tagc", "Set Content mode (\"git\", \"tagc\", \"email\", \"directory\")")

	var filters flagType.FlagType
	flag.Var(&filters, "filter", `Include entrees only matching provided the RegExp (--filter tags=/ISSUE/ --filter commit.email=/(\w)(\w*)(\w)@([^\s]+)/`)
	var removes flagType.FlagType
	var replaces flagType.FlagType
	flag.Var(&removes, "remove", "Remove fields from the output")
	flag.Var(&replaces, "replace", `RegExp to replace text within a field. Example: --replace commit.email=/(\w)(\w*)(\w)@([^\s]+)/${1}*${3}@${4}/ (censors emails it git commits) Optional: Import a replace file with a .rf extention Example: --replace commit.email=/path/to/email/regex.rf`)

	encoding := flag.String("encoding", "text", "Output encoding (json/xml/text/template file path)")

	outputPath := flag.String("output", "stdout", "Output path (must be templated when using encoding template) default stdout")
	cwd := flag.String("dir", ".", "Set the current directory")

	address := flag.String("address", ":6753", "HTTP Address to listen on")
	serve := flag.Bool("serve", false, "Start HTTP Server")

	flag.Parse()

	op := filepath.Join(*cwd, *outputPath)
	enc := strings.ToLower(*encoding)

	var tmpl *template.Template
	var err error
	if enc != "json" && enc != "text" && enc != "xml" {
		templatePath := filepath.Join(*cwd, enc)
		tmpl, err = template.ParseFiles(templatePath)

		if err != nil {
			panic(err)
		}
	}

	// !TODO: Make async so you don't need to store soo much in memory
	// add checks for errors
	

	handle := (func (data interface{}) {
		result := search.One(data, filters.Array(), removes.Array(), replaces.Array(), *cwd)

		var out string
		if enc == "json" {
			out = output.JSON(result)
		} else if enc == "text" {
			out = output.Text(result)
		} else if enc == "xml" {
			out = output.XML(result)
		} else {
			var f bytes.Buffer
			err := tmpl.Execute(&f, result)
			if err != nil {
				fmt.Println("Template path not found: ", filepath.Join(*cwd, enc))
				panic(err)
			}
			out = f.String()
		}

		if *outputPath == "stdout" {
			fmt.Println(out)
		} else {
			p := output.FormatPath(op, result)
			if _, err := os.Stat(filepath.Dir(p)); os.IsNotExist(err) {
				os.MkdirAll(filepath.Dir(p), 0700)
			}
			err := os.WriteFile(p, []byte(out), 0666)
			if err != nil {
				panic(err)
			}
		}
})



	if *mode == "tagc" {
		err := tagc.Read(*path, handle)
		if err != nil {
			panic(err)
		}


	} else if *mode == "git" {
		err := git.Read(*path, handle)
		if err != nil {
			panic(err)
		}

	} else if *mode == "email" {
		inbox := email.Connect(*path, *username, *password)
		inbox.GetMessages("INBOX")

		for _, v := range inbox.Threads {
			handle(v)
		}
		
		inbox.Client.Logout()
	} else if *mode == "directory" {
		err := dir.Read(*path, handle)
		if err != nil {
			panic(err)
		}
	} 

	
	if *serve {
		fs := http.FileServer(http.Dir(*cwd))
		http.Handle("/", fs)

		fmt.Println("Listening on:" + *address)
		fmt.Println("Serving: " + *cwd)
		err := http.ListenAndServe(*address, nil)
		if err != nil {
			panic(err)
		}
	}

	return
}