use new app.ExtraInfo inside minio and donut commands properly

master
Harshavardhana 9 years ago
parent 8346cc74db
commit 0eefbdef0c
  1. 4
      Godeps/Godeps.json
  2. 11
      Godeps/_workspace/src/github.com/minio/cli/app.go
  3. 2
      Godeps/_workspace/src/github.com/minio/cli/help.go
  4. 13
      cmd/donut/main.go
  5. 13
      main.go

4
Godeps/Godeps.json generated vendored

@ -39,8 +39,8 @@
}, },
{ {
"ImportPath": "github.com/minio/cli", "ImportPath": "github.com/minio/cli",
"Comment": "1.2.0-112-g823349c", "Comment": "1.2.0-114-g9280cba",
"Rev": "823349ce91e76834a4af0119d5bbc58fd4d2c6b0" "Rev": "9280cbaadcdd26d50b5ae85123682e37944701de"
}, },
{ {
"ImportPath": "gopkg.in/check.v1", "ImportPath": "gopkg.in/check.v1",

@ -46,7 +46,7 @@ type App struct {
// Compilation date // Compilation date
Compiled string Compiled string
// ExtraInfo pass additional info as a key value map // ExtraInfo pass additional info as a key value map
ExtraInfo map[string]string ExtraInfo func() map[string]string
// List of all authors who contributed // List of all authors who contributed
Authors []Author Authors []Author
// Name of Author (Note: Use App.Authors, this is deprecated) // Name of Author (Note: Use App.Authors, this is deprecated)
@ -125,10 +125,13 @@ func (a *App) Run(arguments []string) (err error) {
}() }()
HelpPrinter = func(templ string, data interface{}) { HelpPrinter = func(templ string, data interface{}) {
funcMap := template.FuncMap{ funcMap := template.FuncMap{}
"join": strings.Join, funcMap["join"] = strings.Join
// if ExtraInfo function
funcMap["ExtraInfo"] = func() map[string]string { return make(map[string]string) }
if a.ExtraInfo != nil {
funcMap["ExtraInfo"] = a.ExtraInfo
} }
w := tabwriter.NewWriter(a.Writer, 0, 8, 1, '\t', 0) w := tabwriter.NewWriter(a.Writer, 0, 8, 1, '\t', 0)
t := template.Must(template.New("help").Funcs(funcMap).Parse(templ)) t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
err := t.Execute(w, data) err := t.Execute(w, data)

@ -25,7 +25,7 @@ VERSION:
{{if .Compiled}} {{if .Compiled}}
BUILD: BUILD:
{{.Compiled}}{{end}} {{.Compiled}}{{end}}
{{range $key, $value := .ExtraInfo}} {{range $key, $value := ExtraInfo}}
{{$value}}{{end}} {{$value}}{{end}}
` `

@ -149,7 +149,6 @@ func main() {
// set up app // set up app
app := cli.NewApp() app := cli.NewApp()
app.Action = runMkdonut
app.Name = "donut" app.Name = "donut"
app.Version = getVersion() app.Version = getVersion()
app.Compiled = getVersion() app.Compiled = getVersion()
@ -158,11 +157,15 @@ func main() {
app.Commands = commands app.Commands = commands
app.Flags = flags app.Flags = flags
app.Before = func(c *cli.Context) error { app.Before = func(c *cli.Context) error {
if c.GlobalBool("debug") { globalDebugFlag = c.GlobalBool("debug")
app.ExtraInfo = getSystemData()
}
return nil return nil
} }
app.ExtraInfo = func() map[string]string {
if globalDebugFlag {
return getSystemData()
}
return make(map[string]string)
}
app.CustomAppHelpTemplate = `NAME: app.CustomAppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}} {{.Name}} - {{.Usage}}
@ -175,7 +178,7 @@ GLOBAL FLAGS:
VERSION: VERSION:
{{if .Compiled}} {{if .Compiled}}
{{.Compiled}}{{end}} {{.Compiled}}{{end}}
{{range $key, $value := .ExtraInfo}} {{range $key, $value := ExtraInfo}}
{{$key}}: {{$key}}:
{{$value}} {{$value}}
{{end}} {{end}}

@ -114,11 +114,16 @@ func main() {
app.Flags = flags app.Flags = flags
app.Commands = commands app.Commands = commands
app.Before = func(c *cli.Context) error { app.Before = func(c *cli.Context) error {
if c.GlobalBool("debug") { globalDebugFlag = c.GlobalBool("debug")
app.ExtraInfo = getSystemData()
}
return nil return nil
} }
app.ExtraInfo = func() map[string]string {
if globalDebugFlag {
return getSystemData()
}
return make(map[string]string)
}
app.CustomAppHelpTemplate = `NAME: app.CustomAppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}} {{.Name}} - {{.Usage}}
@ -134,7 +139,7 @@ GLOBAL FLAGS:
VERSION: VERSION:
{{if .Compiled}} {{if .Compiled}}
{{.Compiled}}{{end}} {{.Compiled}}{{end}}
{{range $key, $value := .ExtraInfo}} {{range $key, $value := ExtraInfo}}
{{$key}}: {{$key}}:
{{$value}} {{$value}}
{{end}} {{end}}

Loading…
Cancel
Save