cmd/utils: customize cli.HelpPrinter to fix alignment (#19956)

This copies cli.printHelp but changes minwidth to 38. Custom flag
code is improved to print the default value using cli.FlagStringer like
all built-in flags do.
This commit is contained in:
SjonHortensius
2019-08-22 13:32:26 +02:00
committed by Felix Lange
parent 1eaf66ae60
commit 4d358b9fc0
2 changed files with 57 additions and 51 deletions

View File

@ -21,12 +21,15 @@ import (
"crypto/ecdsa"
"errors"
"fmt"
"io"
"io/ioutil"
"math/big"
"os"
"path/filepath"
"strconv"
"strings"
"text/tabwriter"
"text/template"
"time"
"github.com/ethereum/go-ethereum/accounts"
@ -90,8 +93,8 @@ GLOBAL OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
cli.CommandHelpTemplate = CommandHelpTemplate
cli.HelpPrinter = printHelp
}
// NewApp creates an app with sane defaults.
@ -105,6 +108,17 @@ func NewApp(gitCommit, gitDate, usage string) *cli.App {
return app
}
func printHelp(out io.Writer, templ string, data interface{}) {
funcMap := template.FuncMap{"join": strings.Join}
t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
w := tabwriter.NewWriter(out, 38, 8, 2, ' ', 0)
err := t.Execute(w, data)
if err != nil {
panic(err)
}
w.Flush()
}
// These are all the command line flags we support.
// If you add to this list, please remember to include the
// flag in the appropriate command definition.
@ -117,7 +131,7 @@ var (
DataDirFlag = DirectoryFlag{
Name: "datadir",
Usage: "Data directory for the databases and keystore",
Value: DirectoryString{node.DefaultDataDir()},
Value: DirectoryString(node.DefaultDataDir()),
}
AncientFlag = DirectoryFlag{
Name: "datadir.ancient",
@ -168,7 +182,7 @@ var (
DocRootFlag = DirectoryFlag{
Name: "docroot",
Usage: "Document Root for HTTPClient file scheme",
Value: DirectoryString{homeDir()},
Value: DirectoryString(homeDir()),
}
ExitWhenSyncedFlag = cli.BoolFlag{
Name: "exitwhensynced",
@ -291,8 +305,8 @@ var (
}
EthashDatasetDirFlag = DirectoryFlag{
Name: "ethash.dagdir",
Usage: "Directory to store the ethash mining DAGs (default = inside home folder)",
Value: DirectoryString{eth.DefaultConfig.Ethash.DatasetDir},
Usage: "Directory to store the ethash mining DAGs",
Value: DirectoryString(eth.DefaultConfig.Ethash.DatasetDir),
}
EthashDatasetsInMemoryFlag = cli.IntFlag{
Name: "ethash.dagsinmem",