mirror of
https://github.com/minio/minio.git
synced 2025-04-01 02:03:42 -04:00
Merge pull request #527 from harshavardhana/pr_out_add_minio_cli_changes_and_add_customapphelptemplate
This commit is contained in:
commit
b01fc9d125
4
Godeps/Godeps.json
generated
4
Godeps/Godeps.json
generated
@ -27,8 +27,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/minio-io/cli",
|
"ImportPath": "github.com/minio-io/cli",
|
||||||
"Comment": "1.2.0-106-g74f4efd",
|
"Comment": "1.2.0-108-g4ad376c",
|
||||||
"Rev": "74f4efdae47555906336b1dcd30c4b40d4d0d6fa"
|
"Rev": "4ad376c97a51a452e36aaa4c19e42560e64be836"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/stretchr/objx",
|
"ImportPath": "github.com/stretchr/objx",
|
||||||
|
15
Godeps/_workspace/src/github.com/minio-io/cli/app.go
generated
vendored
15
Godeps/_workspace/src/github.com/minio-io/cli/app.go
generated
vendored
@ -6,7 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
@ -45,7 +44,7 @@ type App struct {
|
|||||||
// Execute this function if the proper command cannot be found
|
// Execute this function if the proper command cannot be found
|
||||||
CommandNotFound func(context *Context, command string)
|
CommandNotFound func(context *Context, command string)
|
||||||
// Compilation date
|
// Compilation date
|
||||||
Compiled time.Time
|
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 map[string]string
|
||||||
// List of all authors who contributed
|
// List of all authors who contributed
|
||||||
@ -56,20 +55,24 @@ type App struct {
|
|||||||
Email string
|
Email string
|
||||||
// Writer writer to write output to
|
// Writer writer to write output to
|
||||||
Writer io.Writer
|
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
|
// mustCompileTime - determines the modification time of the current binary
|
||||||
func mustCompileTime() time.Time {
|
func mustCompileTime() string {
|
||||||
path, err := exec.LookPath(os.Args[0])
|
path, err := exec.LookPath(os.Args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Time{}
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := os.Stat(path)
|
info, err := os.Stat(path)
|
||||||
if err != nil {
|
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.
|
// NewApp - Creates a new cli Application with some reasonable defaults for Name, Usage, Version and Action.
|
||||||
|
35
Godeps/_workspace/src/github.com/minio-io/cli/app_test.go
generated
vendored
35
Godeps/_workspace/src/github.com/minio-io/cli/app_test.go
generated
vendored
@ -98,41 +98,6 @@ func ExampleAppHelp() {
|
|||||||
// This is how we describe describeit the function
|
// 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) {
|
func TestApp_Run(t *testing.T) {
|
||||||
s := ""
|
s := ""
|
||||||
|
|
||||||
|
24
Godeps/_workspace/src/github.com/minio-io/cli/help.go
generated
vendored
24
Godeps/_workspace/src/github.com/minio-io/cli/help.go
generated
vendored
@ -8,27 +8,25 @@ import (
|
|||||||
// The text template for the Default help topic.
|
// The text template for the Default help topic.
|
||||||
// cli.go uses text/template to render templates. You can
|
// cli.go uses text/template to render templates. You can
|
||||||
// render custom help text by setting this variable.
|
// render custom help text by setting this variable.
|
||||||
var AppHelpTemplate = `NAME:
|
var DefaultAppHelpTemplate = `NAME:
|
||||||
{{.Name}} - {{.Usage}}
|
{{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...]
|
{{.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:
|
COMMANDS:
|
||||||
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
|
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
|
||||||
{{end}}{{if .Flags}}
|
{{end}}{{if .Flags}}
|
||||||
GLOBAL FLAGS:
|
GLOBAL FLAGS:
|
||||||
{{range .Flags}}{{.}}
|
{{range .Flags}}{{.}}
|
||||||
{{end}}{{end}}
|
{{end}}{{end}}
|
||||||
|
VERSION:
|
||||||
|
{{.Version}}
|
||||||
|
{{if .Compiled}}
|
||||||
|
BUILD:
|
||||||
|
{{.Compiled}}{{end}}
|
||||||
|
{{range $key, $value := .ExtraInfo}}
|
||||||
|
{{$value}}{{end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
// The text template for the command help topic.
|
// The text template for the command help topic.
|
||||||
@ -120,7 +118,11 @@ func ShowAppHelp(c *Context) {
|
|||||||
app.Commands = append(app.Commands, command)
|
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
|
// DefaultAppComplete - Prints the list of subcommands as the default app completion method
|
||||||
|
40
main.go
40
main.go
@ -213,6 +213,18 @@ func getWebServerConfigFunc(c *cli.Context) server.StartServerFunc {
|
|||||||
return webDrivers.GetStartServerFunc()
|
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
|
// Tries to get os/arch/platform specific information
|
||||||
// Returns a map of current os/arch/platform/memstats
|
// Returns a map of current os/arch/platform/memstats
|
||||||
func getSystemData() map[string]string {
|
func getSystemData() map[string]string {
|
||||||
@ -242,9 +254,6 @@ func getSystemData() map[string]string {
|
|||||||
// Version is based on MD5SUM of its binary
|
// Version is based on MD5SUM of its binary
|
||||||
var Version = mustHashBinarySelf()
|
var Version = mustHashBinarySelf()
|
||||||
|
|
||||||
// BuildDate - build time
|
|
||||||
var BuildDate string
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// set up iodine
|
// set up iodine
|
||||||
iodine.SetGlobalState("minio.version", Version)
|
iodine.SetGlobalState("minio.version", Version)
|
||||||
@ -254,7 +263,7 @@ func main() {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "minio"
|
app.Name = "minio"
|
||||||
app.Version = Version
|
app.Version = Version
|
||||||
app.Compiled, _ = time.Parse(time.RFC3339Nano, BuildDate)
|
app.Compiled = getBuildDate()
|
||||||
app.Author = "Minio.io"
|
app.Author = "Minio.io"
|
||||||
app.Usage = "Minimalist Object Storage"
|
app.Usage = "Minimalist Object Storage"
|
||||||
app.Flags = flags
|
app.Flags = flags
|
||||||
@ -265,5 +274,28 @@ func main() {
|
|||||||
}
|
}
|
||||||
return nil
|
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()
|
app.RunAndExitOnError()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user