Merge pull request #498 from harshavardhana/pr_out_bring_in_changes_from_minio_io_cli_properly_

Bring in changes from minio-io/cli properly :-)
This commit is contained in:
Harshavardhana 2015-04-26 15:43:29 -07:00
commit 5fe173edf1
10 changed files with 36 additions and 26 deletions

4
Godeps/Godeps.json generated
View File

@ -27,8 +27,8 @@
}, },
{ {
"ImportPath": "github.com/minio-io/cli", "ImportPath": "github.com/minio-io/cli",
"Comment": "1.2.0-102-gecb385c", "Comment": "1.2.0-106-g74f4efd",
"Rev": "ecb385c3fefd53678e3b6beba6a608fb7c8dfac1" "Rev": "74f4efdae47555906336b1dcd30c4b40d4d0d6fa"
}, },
{ {
"ImportPath": "github.com/stretchr/objx", "ImportPath": "github.com/stretchr/objx",

View File

@ -5,7 +5,7 @@ You can view the API docs here:
http://godoc.org/github.com/minio-io/cli http://godoc.org/github.com/minio-io/cli
## Overview ## 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! **This is where cli.go comes into play.** cli.go makes command line programming fun, organized, and expressive!
@ -108,7 +108,7 @@ NAME:
greet - fight the loneliness! greet - fight the loneliness!
USAGE: USAGE:
greet [global options] command [command options] [arguments...] greet [global flags] command [command flags] [arguments...]
VERSION: VERSION:
0.0.0 0.0.0
@ -116,7 +116,7 @@ VERSION:
COMMANDS: COMMANDS:
help, h Shows a list of commands or help for one command help, h Shows a list of commands or help for one command
GLOBAL OPTIONS GLOBAL FLAGS
--version Shows version information --version Shows version information
``` ```
@ -225,7 +225,7 @@ app.Commands = []cli.Command{
{ {
Name: "template", Name: "template",
Aliases: []string{"r"}, Aliases: []string{"r"},
Usage: "options for task templates", Usage: "flags for task templates",
Subcommands: []cli.Command{ Subcommands: []cli.Command{
{ {
Name: "add", Name: "add",

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"os/exec"
"strings" "strings"
"time" "time"
@ -57,12 +58,16 @@ type App struct {
Writer io.Writer Writer io.Writer
} }
// Tries to find out when this binary was compiled. // mustCompileTime - determines the modification time of the current binary
// Returns the current time if it fails to find it. func mustCompileTime() time.Time {
func compileTime() time.Time { path, err := exec.LookPath(os.Args[0])
info, err := os.Stat(os.Args[0])
if err != nil { if err != nil {
return time.Now() return time.Time{}
}
info, err := os.Stat(path)
if err != nil {
return time.Time{}
} }
return info.ModTime() return info.ModTime()
} }
@ -75,7 +80,7 @@ func NewApp() *App {
Version: "0.0.0", Version: "0.0.0",
BashComplete: DefaultAppComplete, BashComplete: DefaultAppComplete,
Action: helpCommand.Action, Action: helpCommand.Action,
Compiled: compileTime(), Compiled: mustCompileTime(),
Writer: os.Stdout, Writer: os.Stdout,
} }
} }

View File

@ -6,7 +6,7 @@ import (
"os" "os"
"testing" "testing"
"github.com/codegangsta/cli" "github.com/minio-io/cli"
) )
func ExampleApp() { func ExampleApp() {

View File

@ -3,7 +3,7 @@ package cli_test
import ( import (
"os" "os"
"github.com/codegangsta/cli" "github.com/minio-io/cli"
) )
func Example() { func Example() {

View File

@ -4,7 +4,7 @@ import (
"flag" "flag"
"testing" "testing"
"github.com/codegangsta/cli" "github.com/minio-io/cli"
) )
func TestCommandDoNotIgnoreFlags(t *testing.T) { func TestCommandDoNotIgnoreFlags(t *testing.T) {

View File

@ -11,7 +11,7 @@ import (
// Context is a type that is passed through to // Context is a type that is passed through to
// each Handler action in a cli application. Context // each Handler action in a cli application. Context
// can be used to retrieve context-specific Args and // can be used to retrieve context-specific Args and
// parsed command-line options. // parsed command-line flags.
type Context struct { type Context struct {
App *App App *App
Command Command Command Command
@ -179,6 +179,11 @@ func (a Args) First() string {
return a.Get(0) 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) // Tail - Return the rest of the arguments (not the first one)
// or else an empty string slice // or else an empty string slice
func (a Args) Tail() []string { func (a Args) Tail() []string {

View File

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/codegangsta/cli" "github.com/minio-io/cli"
) )
func TestNewContext(t *testing.T) { func TestNewContext(t *testing.T) {

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/codegangsta/cli" "github.com/minio-io/cli"
) )
var boolFlagTests = []struct { var boolFlagTests = []struct {

View File

@ -12,7 +12,7 @@ var AppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}} {{.Name}} - {{.Usage}}
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:
{{.Version}} {{.Version}}
@ -26,7 +26,7 @@ BUILD:
COMMANDS: COMMANDS:
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}} {{end}}{{if .Flags}}
GLOBAL OPTIONS: GLOBAL FLAGS:
{{range .Flags}}{{.}} {{range .Flags}}{{.}}
{{end}}{{end}} {{end}}{{end}}
` `
@ -38,12 +38,12 @@ var DefaultCommandHelpTemplate = `NAME:
{{.Name}} - {{.Usage}} {{.Name}} - {{.Usage}}
USAGE: USAGE:
command {{.Name}}{{if .Flags}} [command options]{{end}} [arguments...]{{if .Description}} command {{.Name}}{{if .Flags}} [command flags]{{end}} [arguments...]{{if .Description}}
DESCRIPTION: DESCRIPTION:
{{.Description}}{{end}}{{if .Flags}} {{.Description}}{{end}}{{if .Flags}}
OPTIONS: FLAGS:
{{range .Flags}}{{.}} {{range .Flags}}{{.}}
{{end}}{{ end }} {{end}}{{ end }}
` `
@ -55,12 +55,12 @@ var DefaultSubcommandHelpTemplate = `NAME:
{{.Name}} - {{.Usage}} {{.Name}} - {{.Usage}}
USAGE: USAGE:
{{.Name}} command{{if .Flags}} [command options]{{end}} [arguments...] {{.Name}} command{{if .Flags}} [command flags]{{end}} [arguments...]
COMMANDS: COMMANDS:
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}} {{end}}{{if .Flags}}
OPTIONS: FLAGS:
{{range .Flags}}{{.}} {{range .Flags}}{{.}}
{{end}}{{end}} {{end}}{{end}}
` `