]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: add -template flag to specify custom templates
authorAndrew Gerrand <adg@golang.org>
Tue, 22 Mar 2011 22:44:23 +0000 (09:44 +1100)
committerAndrew Gerrand <adg@golang.org>
Tue, 22 Mar 2011 22:44:23 +0000 (09:44 +1100)
R=gri, niemeyer, rsc1
CC=golang-dev
https://golang.org/cl/4291059

src/cmd/godoc/godoc.go

index 41bd37ad665044e88fc3995cab3aab25e6c7179c..b8e9dbc92672fd8d83d301576c2fec901831fb43 100644 (file)
@@ -65,6 +65,7 @@ var (
        tabwidth       = flag.Int("tabwidth", 4, "tab width")
        showTimestamps = flag.Bool("timestamps", true, "show timestamps with directory listings")
        maxResults     = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
+       templateDir    = flag.String("templates", "", "directory containing alternate template files")
 
        // file system mapping
        fsMap      Mapping // user-defined mapping
@@ -635,6 +636,14 @@ var fmap = template.FormatterMap{
 
 func readTemplate(name string) *template.Template {
        path := filepath.Join(*goroot, "lib", "godoc", name)
+       if *templateDir != "" {
+               defaultpath := path
+               path = filepath.Join(*templateDir, name)
+               if _, err := os.Stat(path); err != nil {
+                       log.Print("readTemplate:", err)
+                       path = defaultpath
+               }
+       }
        data, err := ioutil.ReadFile(path)
        if err != nil {
                log.Fatalf("ReadFile %s: %v", path, err)