From c2d80537876355080b67e57f9bce5b50f0867586 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 26 Apr 2015 15:34:05 -0700 Subject: [PATCH] Bring in changes from minio-io/cli --- Godeps/Godeps.json | 4 ++-- .../src/github.com/minio-io/cli/README.md | 12 ++++++------ .../src/github.com/minio-io/cli/app.go | 17 +++++++++++------ .../src/github.com/minio-io/cli/app_test.go | 2 +- .../src/github.com/minio-io/cli/cli_test.go | 2 +- .../src/github.com/minio-io/cli/command_test.go | 2 +- .../src/github.com/minio-io/cli/context.go | 7 ++++++- .../src/github.com/minio-io/cli/context_test.go | 2 +- .../src/github.com/minio-io/cli/flag_test.go | 2 +- .../src/github.com/minio-io/cli/help.go | 12 ++++++------ 10 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index ea896c339..c09133211 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -27,8 +27,8 @@ }, { "ImportPath": "github.com/minio-io/cli", - "Comment": "1.2.0-102-gecb385c", - "Rev": "ecb385c3fefd53678e3b6beba6a608fb7c8dfac1" + "Comment": "1.2.0-106-g74f4efd", + "Rev": "74f4efdae47555906336b1dcd30c4b40d4d0d6fa" }, { "ImportPath": "github.com/stretchr/objx", diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/README.md b/Godeps/_workspace/src/github.com/minio-io/cli/README.md index 450919513..4c7dddb5f 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/README.md +++ b/Godeps/_workspace/src/github.com/minio-io/cli/README.md @@ -5,7 +5,7 @@ You can view the API docs here: http://godoc.org/github.com/minio-io/cli ## Overview -Command line apps are usually so tiny that there is absolutely no reason why your code should *not* be self-documenting. Things like generating help text and parsing command flags/options should not hinder productivity when writing a command line app. +Command line apps are usually so tiny that there is absolutely no reason why your code should *not* be self-documenting. Things like generating help text and parsing command flags should not hinder productivity when writing a command line app. **This is where cli.go comes into play.** cli.go makes command line programming fun, organized, and expressive! @@ -23,7 +23,7 @@ export PATH=$PATH:$GOPATH/bin ``` ## Getting Started -One of the philosophies behind cli.go is that an API should be playful and full of discovery. So a cli.go app can be as little as one line of code in `main()`. +One of the philosophies behind cli.go is that an API should be playful and full of discovery. So a cli.go app can be as little as one line of code in `main()`. ``` go package main @@ -55,7 +55,7 @@ func main() { app.Action = func(c *cli.Context) { println("boom! I say!") } - + app.Run(os.Args) } ``` @@ -108,7 +108,7 @@ NAME: greet - fight the loneliness! USAGE: - greet [global options] command [command options] [arguments...] + greet [global flags] command [command flags] [arguments...] VERSION: 0.0.0 @@ -116,7 +116,7 @@ VERSION: COMMANDS: help, h Shows a list of commands or help for one command -GLOBAL OPTIONS +GLOBAL FLAGS --version Shows version information ``` @@ -225,7 +225,7 @@ app.Commands = []cli.Command{ { Name: "template", Aliases: []string{"r"}, - Usage: "options for task templates", + Usage: "flags for task templates", Subcommands: []cli.Command{ { Name: "add", 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 b2ac43a16..6caf336c5 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/app.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/app.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "os" + "os/exec" "strings" "time" @@ -57,12 +58,16 @@ type App struct { Writer io.Writer } -// Tries to find out when this binary was compiled. -// Returns the current time if it fails to find it. -func compileTime() time.Time { - info, err := os.Stat(os.Args[0]) +// mustCompileTime - determines the modification time of the current binary +func mustCompileTime() time.Time { + path, err := exec.LookPath(os.Args[0]) if err != nil { - return time.Now() + return time.Time{} + } + + info, err := os.Stat(path) + if err != nil { + return time.Time{} } return info.ModTime() } @@ -75,7 +80,7 @@ func NewApp() *App { Version: "0.0.0", BashComplete: DefaultAppComplete, Action: helpCommand.Action, - Compiled: compileTime(), + Compiled: mustCompileTime(), Writer: os.Stdout, } } 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 0535baa87..c9ed5b853 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 @@ -6,7 +6,7 @@ import ( "os" "testing" - "github.com/codegangsta/cli" + "github.com/minio-io/cli" ) func ExampleApp() { diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/cli_test.go b/Godeps/_workspace/src/github.com/minio-io/cli/cli_test.go index 8a8df9736..96eaf1797 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/cli_test.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/cli_test.go @@ -3,7 +3,7 @@ package cli_test import ( "os" - "github.com/codegangsta/cli" + "github.com/minio-io/cli" ) func Example() { diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/command_test.go b/Godeps/_workspace/src/github.com/minio-io/cli/command_test.go index 4125b0c1b..374eec56b 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/command_test.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/command_test.go @@ -4,7 +4,7 @@ import ( "flag" "testing" - "github.com/codegangsta/cli" + "github.com/minio-io/cli" ) func TestCommandDoNotIgnoreFlags(t *testing.T) { diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/context.go b/Godeps/_workspace/src/github.com/minio-io/cli/context.go index a1ef947fc..5b97b8860 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/context.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/context.go @@ -11,7 +11,7 @@ import ( // Context is a type that is passed through to // each Handler action in a cli application. Context // can be used to retrieve context-specific Args and -// parsed command-line options. +// parsed command-line flags. type Context struct { App *App Command Command @@ -179,6 +179,11 @@ func (a Args) First() string { return a.Get(0) } +// Last - Return the last argument, or else a blank String +func (a Args) Last() string { + return a.Get(len(a) - 1) +} + // Tail - Return the rest of the arguments (not the first one) // or else an empty string slice func (a Args) Tail() []string { diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/context_test.go b/Godeps/_workspace/src/github.com/minio-io/cli/context_test.go index d4a1877f0..b5635960c 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/context_test.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/context_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/codegangsta/cli" + "github.com/minio-io/cli" ) func TestNewContext(t *testing.T) { diff --git a/Godeps/_workspace/src/github.com/minio-io/cli/flag_test.go b/Godeps/_workspace/src/github.com/minio-io/cli/flag_test.go index f0f096a2d..c374dd5a0 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/flag_test.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/flag_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "github.com/codegangsta/cli" + "github.com/minio-io/cli" ) var boolFlagTests = []struct { 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 31c428008..caa219e63 100644 --- a/Godeps/_workspace/src/github.com/minio-io/cli/help.go +++ b/Godeps/_workspace/src/github.com/minio-io/cli/help.go @@ -12,7 +12,7 @@ var AppHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: - {{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...] + {{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...] VERSION: {{.Version}} @@ -26,7 +26,7 @@ BUILD: COMMANDS: {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} {{end}}{{if .Flags}} -GLOBAL OPTIONS: +GLOBAL FLAGS: {{range .Flags}}{{.}} {{end}}{{end}} ` @@ -38,12 +38,12 @@ var DefaultCommandHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: - command {{.Name}}{{if .Flags}} [command options]{{end}} [arguments...]{{if .Description}} + command {{.Name}}{{if .Flags}} [command flags]{{end}} [arguments...]{{if .Description}} DESCRIPTION: {{.Description}}{{end}}{{if .Flags}} -OPTIONS: +FLAGS: {{range .Flags}}{{.}} {{end}}{{ end }} ` @@ -55,12 +55,12 @@ var DefaultSubcommandHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: - {{.Name}} command{{if .Flags}} [command options]{{end}} [arguments...] + {{.Name}} command{{if .Flags}} [command flags]{{end}} [arguments...] COMMANDS: {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} {{end}}{{if .Flags}} -OPTIONS: +FLAGS: {{range .Flags}}{{.}} {{end}}{{end}} `