diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 5ae358d52d20b..41215995c62f7 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -19,6 +19,7 @@ package main import ( "fmt" + "io" "math" "os" "runtime" @@ -26,6 +27,8 @@ import ( "sort" "strconv" "strings" + "text/tabwriter" + "text/template" "time" "github.com/elastic/gosigar" @@ -234,6 +237,26 @@ func init() { app.Flags = append(app.Flags, whisperFlags...) app.Flags = append(app.Flags, metricsFlags...) + // Create a custom printer for minwidth:40 to fix alignment across commands + cli.HelpPrinter = func (out io.Writer, templ string, data interface{}) { + funcMap := template.FuncMap{ + "join": strings.Join, + } + + w := tabwriter.NewWriter(out, 40, 8, 2, ' ', 0) + t := template.Must(template.New("help").Funcs(funcMap).Parse(templ)) + 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") != "" { + log.Crit("CLI TEMPLATE ERROR: %#v\n", err) + } + return + } + w.Flush() + } + app.Before = func(ctx *cli.Context) error { logdir := "" if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) {