Skip to content

Commit

Permalink
Ref #19453 - customize cli.HelpPrinter to fix alignment
Browse files Browse the repository at this point in the history
this copies cli.printHelp but changes minwidth to 40
  • Loading branch information
SjonHortensius committed Aug 13, 2019
1 parent aaf2909 commit 1de9d2a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ package main

import (
"fmt"
"io"
"math"
"os"
"runtime"
godebug "runtime/debug"
"sort"
"strconv"
"strings"
"text/tabwriter"
"text/template"
"time"

"github.com/elastic/gosigar"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1de9d2a

Please sign in to comment.