Go with interfaces + private opaque types
rather than public types that wrap slices
This commit is contained in:
21
help.go
21
help.go
@@ -149,7 +149,7 @@ func ShowCommandHelp(ctx *Context, command string) error {
|
||||
}
|
||||
|
||||
if ctx.App.CommandNotFound == nil {
|
||||
return NewExitError(fmt.Sprintf("No help topic for '%v'", command), 3)
|
||||
return Exit(fmt.Sprintf("No help topic for '%v'", command), 3)
|
||||
}
|
||||
|
||||
ctx.App.CommandNotFound(ctx, command)
|
||||
@@ -201,15 +201,28 @@ func printHelp(out io.Writer, templ string, data interface{}) {
|
||||
|
||||
w := tabwriter.NewWriter(out, 0, 8, 1, '\t', 0)
|
||||
t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
|
||||
|
||||
errDebug := os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != ""
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if errDebug {
|
||||
fmt.Fprintf(ErrWriter, "CLI TEMPLATE PANIC: %#v\n", r)
|
||||
}
|
||||
if os.Getenv("CLI_TEMPLATE_REPANIC") != "" {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err := t.Execute(w, data)
|
||||
if err != nil {
|
||||
// If the writer is closed, t.Execute will fail, and there's nothing
|
||||
// we can do to recover.
|
||||
if os.Getenv("CLI_TEMPLATE_ERROR_DEBUG") != "" {
|
||||
if errDebug {
|
||||
fmt.Fprintf(ErrWriter, "CLI TEMPLATE ERROR: %#v\n", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user