Add 'pwd' and 'go-pwd' variables
This commit is contained in:
parent
32072ab20b
commit
136f9b6fba
13
encoder.go
13
encoder.go
@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
@ -25,6 +26,8 @@ type Ast struct {
|
||||
BuildDate time.Time `json:"build-date"`
|
||||
BuildHostname string `json:"build-hostname"`
|
||||
BuildUser string `json:"build-user"`
|
||||
GoPWD string `json:"go-pwd",omitempty`
|
||||
PWD string `json:"pwd"`
|
||||
Debug bool `json:"debug"`
|
||||
File *descriptor.FileDescriptorProto `json:"file"`
|
||||
Filename string `json:"filename"`
|
||||
@ -86,10 +89,20 @@ func (e *GenericTemplateBasedEncoder) buildContent(templateFilename string) (str
|
||||
}
|
||||
|
||||
hostname, _ := os.Hostname()
|
||||
pwd, _ := os.Getwd()
|
||||
goPwd := ""
|
||||
if os.Getenv("GOPATH") != "" {
|
||||
goPwd, _ = filepath.Rel(os.Getenv("GOPATH")+"/src", pwd)
|
||||
if strings.Contains(goPwd, "../") {
|
||||
goPwd = ""
|
||||
}
|
||||
}
|
||||
ast := Ast{
|
||||
BuildDate: time.Now(),
|
||||
BuildHostname: hostname,
|
||||
BuildUser: os.Getenv("USER"),
|
||||
PWD: pwd,
|
||||
GoPWD: goPwd,
|
||||
File: e.file,
|
||||
Filename: templateFilename,
|
||||
Service: e.service,
|
||||
|
@ -1,7 +1,9 @@
|
||||
{
|
||||
"build-date": "2016-11-07T09:21:48.495773574+01:00",
|
||||
"build-date": "2016-11-07T10:27:35.986181944+01:00",
|
||||
"build-hostname": "moul-rose.local",
|
||||
"build-user": "moul",
|
||||
"go-pwd": "github.com/moul/protoc-gen-gotemplate/examples/dummy",
|
||||
"pwd": "/Users/moul/go/src/github.com/moul/protoc-gen-gotemplate/examples/dummy",
|
||||
"debug": false,
|
||||
"file": {
|
||||
"name": "dummy.proto",
|
||||
|
Loading…
x
Reference in New Issue
Block a user