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
diff --git a/options.go b/options.go
index 9b8e135..28f38d2 100644
--- a/options.go
+++ b/options.go
@@ -10,6 +10,7 @@ import (
type options struct {
Branches manyflag `json:"branches"`
config string
+ Export bool `json:"export"`
Force bool `json:"force"`
Name string `json:"name"`
Quiet bool `json:"quiet"`