Skip to content
Permalink
Browse files

Install target

  • Loading branch information...
Depado committed Oct 23, 2018
1 parent 2501fb5 commit bdbd501a86d3bc86bdd017c299f4e121ef7d1cfb
Showing with 42 additions and 4 deletions.
  1. +4 −0 Makefile
  2. +9 −0 README.md
  3. +2 −2 conf/file.go
  4. +27 −2 conf/variables.go
@@ -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
@@ -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
@@ -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 != "" {
@@ -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
}
}
}

0 comments on commit bdbd501

Please sign in to comment.
You can’t perform that action at this time.