gshr
git static host repo -- generates static html for repos
git clone https://git.vogt.world/gshr.git
Log | Files | README.md | LICENSE
← Commit log
commit
message
More flag stuff
author
Ben Vogt <[email protected]>
date
2023-04-03 21:04:40
stats
2 file(s) changed, 17 insertions(+), 6 deletions(-)
files
Makefile
main.go
 1diff --git a/Makefile b/Makefile
 2index 966f437..95f6d58 100644
 3--- a/Makefile
 4+++ b/Makefile
 5@@ -24,8 +24,10 @@ target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin:
 6 
 7 dev: target output cloning target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin
 8 	./target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin \
 9+    --repo=/Users/bvogt/dev/src/ben/www \
10     --output=$(PWD)/target/output \
11-    --clone=$(PWD)/target/cloning && \
12+    --clone=$(PWD)/target/cloning \
13+		&& \
14     cp styles.css $(PWD)/target/output/ && \
15     cd $(PWD)/target/output && \
16     python3 -m http.server 8000
17\ No newline at end of file
18diff --git a/main.go b/main.go
19index 7115954..a90d47a 100644
20--- a/main.go
21+++ b/main.go
22@@ -2,6 +2,7 @@ package main
23 
24 import (
25 	"bytes"
26+	"errors"
27 	"flag"
28 	"fmt"
29 	"html/template"
30@@ -21,6 +22,7 @@ import (
31 
32 var (
33 	debugOn        = true
34+	repo           = ""
35 	outputDir      = ""
36 	cloningDir     = ""
37 	textExtensions = map[string]bool{
38@@ -58,11 +60,16 @@ var (
39 )
40 
41 func main() {
42-	flag.BoolVar(&debugOn, "debug", true, "debug mode")
43-	flag.StringVar(&outputDir, "output", "", "clone directory")
44-	flag.StringVar(&cloningDir, "clone", "", "clone directory")
45+	flag.StringVar(&repo, "repo", "", "Repo to use.")
46+	flag.BoolVar(&debugOn, "debug", true, "Run in debug mode.")
47+	flag.StringVar(&outputDir, "output", "", "Directory of output.")
48+	flag.StringVar(&cloningDir, "clone", "", "Directory to clone into. Random directory in /tmp if omitted.")
49 	flag.Parse()
50 
51+	if repo == "" {
52+		checkErr(errors.New("--repo flag is required"))
53+	}
54+
55 	if cloningDir == "" {
56 		cloningDir = fmt.Sprintf("/tmp/gshr-temp-clone-%v", rand.Uint32())
57 	}
58@@ -156,7 +163,7 @@ func (fi *FilesIndex) SaveTemplate(t *template.Template) {
59 
60 func CloneAndInfo() *git.Repository {
61 	r, err := git.PlainClone(cloningDir, false, &git.CloneOptions{
62-		URL: "/Users/bvogt/dev/src/ben/www",
63+		URL: repo,
64 	})
65 	checkErr(err)
66 	return r
67@@ -250,7 +257,7 @@ func BuildSingleFilePages() {
68 
69 func checkErr(err error) {
70 	if err != nil {
71-		fmt.Println(err)
72+		fmt.Printf("ERROR: %v\n", err)
73 		os.Exit(1)
74 	}
75 }