Update codegangsta with upstream

This commit is contained in:
Harshavardhana
2015-03-15 02:23:27 -07:00
parent 4d7ab9e204
commit bbd3d51dfa
10 changed files with 384 additions and 89 deletions
+18 -26
View File
@@ -1,11 +1,6 @@
package cli
import (
"fmt"
"os"
"text/tabwriter"
"text/template"
)
import "fmt"
// The text template for the Default help topic.
// cli.go uses text/template to render templates. You can
@@ -17,11 +12,10 @@ USAGE:
{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
VERSION:
{{.Version}}{{if or .Author .Email}}
{{.Version}}
AUTHOR:{{if .Author}}
{{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}}
{{.Email}}{{end}}{{end}}
AUTHOR(S):
{{range .Authors}}{{ . }} {{end}}
COMMANDS:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
@@ -94,7 +88,9 @@ var helpSubcommand = Command{
}
// Prints help for the App
var HelpPrinter = printHelp
type helpPrinter func(templ string, data interface{})
var HelpPrinter helpPrinter = nil
// Prints version for the App
var VersionPrinter = printVersion
@@ -106,15 +102,21 @@ func ShowAppHelp(c *Context) {
// Prints the list of subcommands as the default app completion method
func DefaultAppComplete(c *Context) {
for _, command := range c.App.Commands {
fmt.Println(command.Name)
fmt.Fprintln(c.App.Writer, command.Name)
if command.ShortName != "" {
fmt.Println(command.ShortName)
fmt.Fprintln(c.App.Writer, command.ShortName)
}
}
}
// Prints help for the given command
func ShowCommandHelp(c *Context, command string) {
// show the subcommand help for a command with subcommands
if command == "" {
HelpPrinter(SubcommandHelpTemplate, c.App)
return
}
for _, c := range c.App.Commands {
if c.HasName(command) {
HelpPrinter(CommandHelpTemplate, c)
@@ -125,13 +127,13 @@ func ShowCommandHelp(c *Context, command string) {
if c.App.CommandNotFound != nil {
c.App.CommandNotFound(c, command)
} else {
fmt.Printf("No help topic for '%v'\n", command)
fmt.Fprintf(c.App.Writer, "No help topic for '%v'\n", command)
}
}
// Prints help for the given subcommand
func ShowSubcommandHelp(c *Context) {
HelpPrinter(SubcommandHelpTemplate, c.App)
ShowCommandHelp(c, c.Command.Name)
}
// Prints the version number of the App
@@ -140,7 +142,7 @@ func ShowVersion(c *Context) {
}
func printVersion(c *Context) {
fmt.Printf("%v version %v\n", c.App.Name, c.App.Version)
fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version)
}
// Prints the lists of commands within a given context
@@ -159,16 +161,6 @@ func ShowCommandCompletions(ctx *Context, command string) {
}
}
func printHelp(templ string, data interface{}) {
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
t := template.Must(template.New("help").Parse(templ))
err := t.Execute(w, data)
if err != nil {
panic(err)
}
w.Flush()
}
func checkVersion(c *Context) bool {
if c.GlobalBool("version") {
ShowVersion(c)