Bring in changes from minio-io/cli

This commit is contained in:
root 2015-04-26 15:34:05 -07:00
parent a3af3514ca
commit c2d8053787
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",
"Comment": "1.2.0-102-gecb385c",
"Rev": "ecb385c3fefd53678e3b6beba6a608fb7c8dfac1"
"Comment": "1.2.0-106-g74f4efd",
"Rev": "74f4efdae47555906336b1dcd30c4b40d4d0d6fa"
},
{
"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
## 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",

View File

@ -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,
}
}

View File

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

View File

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

View File

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

View File

@ -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 {

View File

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

View File

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

View File

@ -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}}
`