Skip to content

Commit

Permalink
Install target
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Lhussiez committed Oct 23, 2018
1 parent 2501fb5 commit bdbd501
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions conf/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 != "" {
Expand Down
29 changes: 27 additions & 2 deletions conf/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit bdbd501

Please sign in to comment.