Skip to content

Commit

Permalink
Merge pull request #29 from gondor/master
Browse files Browse the repository at this point in the history
fix templates on go 1.6
  • Loading branch information
gondor committed Jun 1, 2016
2 parents c38bae5 + b531e34 commit f508eed
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 0.8.5
VERSION = 0.8.7

GO_FMT = gofmt -s -w -l .
GO_XC = goxc -os="linux darwin windows" -tasks-="rmbin"
Expand Down
15 changes: 7 additions & 8 deletions commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ const (
{{end}}`
)


type ConfigEnvironments struct {
DefaultEnv string
Envs map[string]*cliconfig.ConfigEnvironment
}

type EnvironmentSummary struct {
Name string
Name string
EnvType string
HostURL string
Auth bool
Auth bool
Default bool
}

Expand Down Expand Up @@ -173,7 +172,7 @@ type ConfigTemplate struct {
}

func templateFor(template string, data interface{}) ConfigTemplate {
return ConfigTemplate{cli.FormatData{ Template: template, Data: data, Funcs: buildFuncMap() }}
return ConfigTemplate{cli.FormatData{Template: template, Data: data, Funcs: buildFuncMap()}}
}

func (d ConfigTemplate) ToColumns(output io.Writer) error {
Expand All @@ -195,10 +194,10 @@ func (e ConfigEnvironments) toEnvironmentMap() []*EnvironmentSummary {
sc = *v.Marathon
}
arr = append(arr, &EnvironmentSummary{
Name: k,
Name: k,
EnvType: v.EnvironmentType(),
HostURL: sc.HostUrl,
Auth: sc.Username != "",
Auth: sc.Username != "",
Default: k == e.DefaultEnv,
})
}
Expand All @@ -207,7 +206,7 @@ func (e ConfigEnvironments) toEnvironmentMap() []*EnvironmentSummary {

func buildFuncMap() template.FuncMap {
funcMap := template.FuncMap{
"defaultEnvToStr": defaultEnvToStr,
"defaultEnvToStr": defaultEnvToStr,
}
return funcMap
}
Expand All @@ -217,4 +216,4 @@ func defaultEnvToStr(b bool) string {
return "true"
}
return "-"
}
}
1 change: 0 additions & 1 deletion commands/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ func printColumn(formatter cli.Formatter) {
log.Error("Error: %s", err.Error())
}
}

2 changes: 1 addition & 1 deletion commands/marathon/app_bg_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func deployBlueGreenCmd(cmd *cobra.Command, args []string) {
cli.Output(nil, err)
os.Exit(1)
}
cli.Output(templateFor(T_APPLICATIONS, a), err)
cli.Output(templateFor(T_APPLICATION, a), err)
}

func bgc(c *cobra.Command) bluegreen.BlueGreen {
Expand Down
9 changes: 5 additions & 4 deletions commands/marathon/app_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var appListCmd = &cobra.Command{
Short: "List all applications",
Run: func(cmd *cobra.Command, args []string) {
v, e := client(cmd).ListApplications()

cli.Output(templateFor(T_APPLICATIONS, v), e)
},
}
Expand Down Expand Up @@ -175,7 +176,7 @@ func createApp(cmd *cobra.Command, args []string) {
}
os.Exit(1)
}
cli.Output(templateFor(T_APPLICATIONS, result), e)
cli.Output(templateFor(T_APPLICATION, result), e)
}

func parseParamsFile(filename string) (map[string]string, error) {
Expand Down Expand Up @@ -251,7 +252,7 @@ func updateAppCPU(cmd *cobra.Command, args []string) {
}
update := marathon.NewApplication(args[0]).CPU(cpu)
v, e := client(cmd).UpdateApplication(update, wait)
cli.Output(templateFor(T_APPLICATIONS, v), e)
cli.Output(templateFor(T_APPLICATION, v), e)
}

func updateAppMemory(cmd *cobra.Command, args []string) {
Expand All @@ -268,7 +269,7 @@ func updateAppMemory(cmd *cobra.Command, args []string) {
}
update := marathon.NewApplication(args[0]).Memory(mem)
v, e := client(cmd).UpdateApplication(update, wait)
cli.Output(templateFor(T_APPLICATIONS, v), e)
cli.Output(templateFor(T_APPLICATION, v), e)
}

func rollbackAppVersion(cmd *cobra.Command, args []string) {
Expand All @@ -289,7 +290,7 @@ func rollbackAppVersion(cmd *cobra.Command, args []string) {
}
update := marathon.NewApplication(args[0]).RollbackVersion(version)
v, e := client(cmd).UpdateApplication(update, wait)
cli.Output(templateFor(T_APPLICATIONS, v), e)
cli.Output(templateFor(T_APPLICATION, v), e)
}

func convertFile(cmd *cobra.Command, args []string) {
Expand Down
15 changes: 7 additions & 8 deletions commands/marathon/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package marathon

import (
"github.com/ContainX/depcon/marathon"
"github.com/ContainX/depcon/utils"
"text/template"
"github.com/ContainX/depcon/pkg/cli"
"github.com/ContainX/depcon/utils"
"io"
"text/template"
)

const (
Expand Down Expand Up @@ -113,7 +113,7 @@ type Templated struct {
}

func templateFor(template string, data interface{}) Templated {
return Templated{cli.FormatData{ Template: template, Data: data, Funcs: buildFuncMap() }}
return Templated{cli.FormatData{Template: template, Data: data, Funcs: buildFuncMap()}}
}

func (d Templated) ToColumns(output io.Writer) error {
Expand All @@ -124,13 +124,12 @@ func (d Templated) Data() cli.FormatData {
return d.FormatData
}


func buildFuncMap() template.FuncMap {
funcMap := template.FuncMap{
"intConcat": utils.ConcatInts,
"idConcat": utils.ConcatIdentifiers,
"dockerImage": dockerImageOrEmpty,
"hasDocker": hasDocker,
"intConcat": utils.ConcatInts,
"idConcat": utils.ConcatIdentifiers,
"dockerImage": dockerImageOrEmpty,
"hasDocker": hasDocker,
}
return funcMap
}
Expand Down
1 change: 0 additions & 1 deletion marathon/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const (
var (
ErrorAppExists = errors.New("The application already exists")
ErrorGroupExists = errors.New("The group already exists")
ErrorInvalidAppId = errors.New("The application identifier is invalid")
ErrorInvalidGroupId = errors.New("The group identifier is invalid")
ErrorNoAppExists = errors.New("The application does not exist. Create an application before updating")
ErrorGropAppExists = errors.New("The group does not exist. Create a group before updating")
Expand Down
11 changes: 5 additions & 6 deletions pkg/cli/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package cli
import (
"fmt"
"io"
"text/tabwriter"
"strconv"
"text/tabwriter"
"text/template"
"time"
)
Expand All @@ -18,10 +18,9 @@ type Formatter interface {
type FormatData struct {
Data interface{}
Template string
Funcs template.FuncMap
Funcs template.FuncMap
}


// Handles writing the formatted type into the desired output and global formatting
type CLIWriter struct {
FormatWriter func(f Formatter)
Expand Down Expand Up @@ -68,10 +67,10 @@ func buildFuncMap(userFuncs template.FuncMap) template.FuncMap {
funcMap := template.FuncMap{
"floatToString": floatToString,
"intToString": strconv.Itoa,
"valString": valueToString,
"valString": valueToString,
"pad": padString,
"fdate": FormatDate,
"msDur": durationToMilliseconds,
"fdate": FormatDate,
"msDur": durationToMilliseconds,
"boolToYesNo": boolToYesNo,
}

Expand Down

0 comments on commit f508eed

Please sign in to comment.