gtx


Branch: develop

Author
thewhodidthis <thewhodidthis@fastmail.com>
Date
Jan. 31 '23 19:41:35
Commit
d0be697148c0e2b48c0b916c028201e3e53c5cf6
Parent
c67ecd512a532594eeb52dfd43646adfe2a1d00f
Changes
diff --git a/main.go b/main.go
index 2884466..32324dc 100644
--- a/main.go
+++ b/main.go
@@ -45,6 +45,7 @@ func main() {
 	flag.Var(&opt.Branches, "b", "Target branches")
 	flag.StringVar(&opt.Template, "t", "", "Page template")
 	flag.BoolVar(&opt.Quiet, "q", false, "Be quiet")
+	flag.BoolVar(&opt.Export, "e", false, "Export default template")
 	flag.BoolVar(&opt.Force, "f", false, "Force rebuild")
 	flag.Parse()
 
@@ -52,16 +53,6 @@ func main() {
 		log.SetOutput(io.Discard)
 	}
 
-	if opt.Template != "" {
-		bs, err := os.ReadFile(opt.Template)
-
-		if err != nil {
-			log.Printf("unable to read template: %v", err)
-		} else {
-			tpl = string(bs)
-		}
-	}
-
 	cwd, err := os.Getwd()
 
 	if err != nil {
@@ -76,6 +67,25 @@ func main() {
 		dir = filepath.Join(cwd, dir)
 	}
 
+	if opt.Export {
+		if err := os.WriteFile(filepath.Join(dir, "page.html.tmpl"), []byte(tpl), 0644); err != nil {
+			log.Fatalf("unable to export default template: %v", err)
+		}
+
+		log.Printf("done exporting default template")
+		return
+	}
+
+	if opt.Template != "" {
+		bs, err := os.ReadFile(opt.Template)
+
+		if err != nil {
+			log.Printf("unable to read template: %v", err)
+		} else {
+			tpl = string(bs)
+		}
+	}
+
 	// Create a separate options instance for reading config file values into.
 	store := *opt