From bdbd501a86d3bc86bdd017c299f4e121ef7d1cfb Mon Sep 17 00:00:00 2001 From: Paul Lhussiez Date: Tue, 23 Oct 2018 18:20:46 +0200 Subject: [PATCH] Install target --- Makefile | 4 ++++ README.md | 9 +++++++++ conf/file.go | 4 ++-- conf/variables.go | 29 +++++++++++++++++++++++++++-- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f582549..df18406 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,10 @@ help: build: ## Build CGO_ENABLED=0 go build -o $(BINARY) $(LDFLAGS) +.PHONY: install +install: ## Build and install + CGO_ENABLED=0 go install $(LDFLAGS) + .PHONY: release release: ## Create a new release on Github VERSION=$(VERSION) BUILD=$(BUILD) goreleaser diff --git a/README.md b/README.md index 1178997..3f78cdd 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,15 @@ $ dep ensure $ make ``` +Or directly install: + +``` +$ go get -u github.com/Depado/projectmpl +$ cd $GOPATH/src/github.com/Depado/projectpml +$ dep ensure +$ make install +``` + # Usage Projectmpl supports various provider to download the templates. It supports diff --git a/conf/file.go b/conf/file.go index c92d378..ee21e6a 100644 --- a/conf/file.go +++ b/conf/file.go @@ -173,8 +173,8 @@ func (f *File) Render() error { var condition string var copy bool var ignore bool - var ctx map[string]interface{} + ctx := make(map[string]interface{}) delims := []string{"{{", "}}"} for i := len(f.Renderers) - 1; i >= 0; i-- { r := f.Renderers[i] @@ -184,13 +184,13 @@ func (f *File) Render() error { if r.Ignore != nil { ignore = *r.Ignore } - ctx = r.Variables.Ctx() if r.Delimiters != nil { if len(r.Delimiters) != 2 { return fmt.Errorf("Delimiters should be an array of two string") } delims = r.Delimiters } + r.Variables.AddToCtx("", ctx) } if f.Metadata != nil { if f.Metadata.If != "" { diff --git a/conf/variables.go b/conf/variables.go index c6f1be1..248081c 100644 --- a/conf/variables.go +++ b/conf/variables.go @@ -12,6 +12,27 @@ import ( // Variables represents a map of variable type Variables map[string]*Variable +// func (e *Variables) UnmarshalYAML(unmarshal func(interface{}) error) error { +// n := yaml.MapSlice{} +// err := unmarshal(&n) +// if err != nil { +// return err +// } +// for _, v := range n { +// var inv &Variable +// fmt.Println("============") +// fmt.Println(v.Key) +// for _, vv := range v.Value.(yaml.MapSlice) { +// switch vv.Key { +// case "default": + +// } +// fmt.Println("\t", vv.Key, vv.Value) +// } +// } +// return nil +// } + // Prompt will prompt the variables func (vv Variables) Prompt() { // Order the variables alphabetically to keep the same order @@ -52,9 +73,13 @@ func (vv Variables) Ctx() map[string]interface{} { } // AddToCtx will add the variable results to a sub-key -func (vv Variables) AddToCtx(key string, ctx map[string]interface{}) { +func (vv Variables) AddToCtx(prefix string, ctx map[string]interface{}) { for k, v := range vv.Ctx() { - ctx[key+"_"+k] = v + if prefix != "" { + ctx[prefix+"_"+k] = v + } else { + ctx[k] = v + } } }