Skip to content
This repository was archived by the owner on Jul 29, 2021. It is now read-only.

Commit e7bb543

Browse files
authored
Merge pull request #14 from melekes/master
Provide a way to supply an alternative template file
2 parents b2a16b2 + e4ad6cf commit e7bb543

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

main.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"flag"
1616
"fmt"
1717
"go/build"
18+
"io/ioutil"
1819
"log"
1920
"os"
2021
"path"
@@ -37,7 +38,7 @@ var (
3738
// layout control
3839
tabWidth = flag.Int("tabwidth", 4, "tab width")
3940
showTimestamps = flag.Bool("timestamps", false, "show timestamps with directory listings")
40-
templateDir = flag.String("templates", "", "directory containing alternate template files")
41+
altPkgTemplate = flag.String("template", "", "path to an alternate template file")
4142
showPlayground = flag.Bool("play", false, "enable playground in web interface")
4243
showExamples = flag.Bool("ex", false, "show examples in command line mode")
4344
declLinks = flag.Bool("links", true, "link identifiers to their declarations")
@@ -89,10 +90,6 @@ func readTemplate(name, data string) *template.Template {
8990
return t
9091
}
9192

92-
func readTemplates(p *godoc.Presentation, html bool) {
93-
p.PackageText = readTemplate("package.txt", pkgTemplate)
94-
}
95-
9693
func main() {
9794
flag.Usage = usage
9895
flag.Parse()
@@ -122,7 +119,15 @@ func main() {
122119
pres.SrcMode = false
123120
pres.HTMLMode = false
124121

125-
readTemplates(pres, false)
122+
if *altPkgTemplate != "" {
123+
buf, err := ioutil.ReadFile(*altPkgTemplate)
124+
if err != nil {
125+
log.Fatal(err)
126+
}
127+
pres.PackageText = readTemplate("package.txt", string(buf))
128+
} else {
129+
pres.PackageText = readTemplate("package.txt", pkgTemplate)
130+
}
126131

127132
if err := godoc.CommandLine(os.Stdout, fs, pres, flag.Args()); err != nil {
128133
log.Print(err)

0 commit comments

Comments
 (0)