From 76701187e3eefc15907eff90cd0ae3e82c6b2d22 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 28 Apr 2015 21:16:10 -0700 Subject: [PATCH] Add minio cli changes and add CustomAppHelpTemplate --- Godeps/Godeps.json | 4 +- .../src/github.com/minio-io/cli/app.go | 15 ++++--- .../src/github.com/minio-io/cli/app_test.go | 35 ---------------- .../src/github.com/minio-io/cli/help.go | 24 ++++++----- main.go | 40 +++++++++++++++++-- 5 files changed, 60 insertions(+), 58 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index c268c0fd5..090549db5 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -27,8 +27,8 @@ }, { "ImportPath": "github.com/minio-io/cli", - "Comment": "1.2.0-106-g74f4efd", - "Rev": "74f4efdae47555906336b1dcd30c4b40d4d0d6fa" + "Comment": "1.2.0-108-g4ad376c", + "Rev": "4ad376c97a51a452e36aaa4c19e42560e64be836" }, { "ImportPath": "github.com/stretchr/objx", diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/app.go b/Godeps/_workspace/src/github.com/minio-io/cli/app.go index 6caf336c5..57f1a8872 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/app.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/app.go @@ -6,7 +6,6 @@ import ( "os" "os/exec" "strings" - "time" "io/ioutil" "text/tabwriter" @@ -45,7 +44,7 @@ type App struct { // Execute this function if the proper command cannot be found CommandNotFound func(context *Context, command string) // Compilation date - Compiled time.Time + Compiled string // ExtraInfo pass additional info as a key value map ExtraInfo map[string]string // List of all authors who contributed @@ -56,20 +55,24 @@ type App struct { Email string // Writer writer to write output to Writer io.Writer + // CustomAppHelpTemplate the text template for app help topic. + // cli.go uses text/template to render templates. You can + // render custom help text by setting this variable. + CustomAppHelpTemplate string } // mustCompileTime - determines the modification time of the current binary -func mustCompileTime() time.Time { +func mustCompileTime() string { path, err := exec.LookPath(os.Args[0]) if err != nil { - return time.Time{} + return "" } info, err := os.Stat(path) if err != nil { - return time.Time{} + return "" } - return info.ModTime() + return info.ModTime().String() } // NewApp - Creates a new cli Application with some reasonable defaults for Name, Usage, Version and Action. diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/app_test.go b/Godeps/_workspace/src/github.com/minio-io/cli/app_test.go index c9ed5b853..a7c9fd704 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/app_test.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/app_test.go @@ -98,41 +98,6 @@ func ExampleAppHelp() { // This is how we describe describeit the function } -func ExampleAppBashComplete() { - // set args for examples sake - os.Args = []string{"greet", "--generate-bash-completion"} - - app := cli.NewApp() - app.Name = "greet" - app.EnableBashCompletion = true - app.Commands = []cli.Command{ - { - Name: "describeit", - Aliases: []string{"d"}, - Usage: "use it to see a description", - Description: "This is how we describe describeit the function", - Action: func(c *cli.Context) { - fmt.Printf("i like to describe things") - }, - }, { - Name: "next", - Usage: "next example", - Description: "more stuff to see when generating bash completion", - Action: func(c *cli.Context) { - fmt.Printf("the next example") - }, - }, - } - - app.Run(os.Args) - // Output: - // describeit - // d - // next - // help - // h -} - func TestApp_Run(t *testing.T) { s := "" diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/help.go b/Godeps/_workspace/src/github.com/minio-io/cli/help.go index caa219e63..cb36641c4 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/help.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/help.go @@ -8,27 +8,25 @@ import ( // The text template for the Default help topic. // cli.go uses text/template to render templates. You can // render custom help text by setting this variable. -var AppHelpTemplate = `NAME: +var DefaultAppHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: {{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...] -VERSION: - {{.Version}} - -BUILD: - {{.Compiled}} -{{range $key, $value := .ExtraInfo}} -{{ $key }}: - {{ $value }} -{{ end }} COMMANDS: {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} {{end}}{{if .Flags}} GLOBAL FLAGS: {{range .Flags}}{{.}} {{end}}{{end}} +VERSION: + {{.Version}} +{{if .Compiled}} +BUILD: + {{.Compiled}}{{end}} +{{range $key, $value := .ExtraInfo}} +{{$value}}{{end}} ` // The text template for the command help topic. @@ -120,7 +118,11 @@ func ShowAppHelp(c *Context) { app.Commands = append(app.Commands, command) } } - HelpPrinter(AppHelpTemplate, app) + if app.CustomAppHelpTemplate != "" { + HelpPrinter(app.CustomAppHelpTemplate, app) + } else { + HelpPrinter(DefaultAppHelpTemplate, app) + } } // DefaultAppComplete - Prints the list of subcommands as the default app completion method diff --git a/main.go b/main.go index 27ac415de..837f12d1a 100644 --- a/main.go +++ b/main.go @@ -213,6 +213,18 @@ func getWebServerConfigFunc(c *cli.Context) server.StartServerFunc { return webDrivers.GetStartServerFunc() } +// Build date +var BuildDate string + +// getBuildDate - +func getBuildDate() string { + if BuildDate == "" { + return "" + } + t, _ := time.Parse(time.RFC3339Nano, BuildDate) + return t.String() +} + // Tries to get os/arch/platform specific information // Returns a map of current os/arch/platform/memstats func getSystemData() map[string]string { @@ -242,9 +254,6 @@ func getSystemData() map[string]string { // Version is based on MD5SUM of its binary var Version = mustHashBinarySelf() -// BuildDate - build time -var BuildDate string - func main() { // set up iodine iodine.SetGlobalState("minio.version", Version) @@ -254,7 +263,7 @@ func main() { app := cli.NewApp() app.Name = "minio" app.Version = Version - app.Compiled, _ = time.Parse(time.RFC3339Nano, BuildDate) + app.Compiled = getBuildDate() app.Author = "Minio.io" app.Usage = "Minimalist Object Storage" app.Flags = flags @@ -265,5 +274,28 @@ func main() { } return nil } + app.CustomAppHelpTemplate = `NAME: + {{.Name}} - {{.Usage}} + +USAGE: + {{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...] + +COMMANDS: + {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} + {{end}}{{if .Flags}} +GLOBAL FLAGS: + {{range .Flags}}{{.}} + {{end}}{{end}} +VERSION: + {{.Version}} + {{if .Compiled}} +BUILD: + {{.Compiled}}{{end}} + {{range $key, $value := .ExtraInfo}} +{{$key}}: + {{$value}} +{{end}} +` + app.RunAndExitOnError() }