Bring in changes from minio-io/cli properly :-)

master
Harshavardhana 10 years ago
parent 9bc0f61191
commit 6332a8d108
  1. 4
      Godeps/Godeps.json
  2. 12
      Godeps/_workspace/src/github.com/minio-io/cli/README.md
  3. 17
      Godeps/_workspace/src/github.com/minio-io/cli/app.go
  4. 2
      Godeps/_workspace/src/github.com/minio-io/cli/app_test.go
  5. 2
      Godeps/_workspace/src/github.com/minio-io/cli/cli_test.go
  6. 2
      Godeps/_workspace/src/github.com/minio-io/cli/command_test.go
  7. 7
      Godeps/_workspace/src/github.com/minio-io/cli/context.go
  8. 2
      Godeps/_workspace/src/github.com/minio-io/cli/context_test.go
  9. 2
      Godeps/_workspace/src/github.com/minio-io/cli/flag_test.go
  10. 12
      Godeps/_workspace/src/github.com/minio-io/cli/help.go

4
Godeps/Godeps.json generated vendored

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

@ -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!
@ -23,7 +23,7 @@ export PATH=$PATH:$GOPATH/bin
``` ```
## Getting Started ## 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 ``` go
package main package main
@ -55,7 +55,7 @@ func main() {
app.Action = func(c *cli.Context) { app.Action = func(c *cli.Context) {
println("boom! I say!") println("boom! I say!")
} }
app.Run(os.Args) app.Run(os.Args)
} }
``` ```
@ -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",

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

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

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

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

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

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

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

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

Loading…
Cancel
Save