From 428afc5e1a58b0d2589dd40d9d9855f8440515a1 Mon Sep 17 00:00:00 2001 From: renaynay <41963722+renaynay@users.noreply.github.com> Date: Tue, 28 Apr 2020 11:14:52 +0200 Subject: [PATCH] uncategorized flags, if not deprecated, displayed under misc --- cmd/geth/usage.go | 30 ++++++++++++++++++++++++++++++ cmd/utils/flags_legacy.go | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index d1d61a6b0a..c31c5d9657 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -315,6 +315,36 @@ func init() { originalHelpPrinter := cli.HelpPrinter cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) { if tmpl == AppHelpTemplate { + // Iterate over all the flags and add any uncategorized ones + categorized := make(map[string]struct{}) + for _, group := range AppHelpFlagGroups { + for _, flag := range group.Flags { + categorized[flag.String()] = struct{}{} + } + } + deprecated := make(map[string]struct{}) + for _, flag := range utils.DeprecatedFlags { + deprecated[flag.String()] = struct{}{} + } + // Only add uncategorized flags if they are not deprecated + var uncategorized []cli.Flag + for _, flag := range data.(*cli.App).Flags { + if _, ok := categorized[flag.String()]; !ok { + if _, ok := deprecated[flag.String()]; !ok { + uncategorized = append(uncategorized, flag) + } + } + } + if len(uncategorized) > 0 { + // Append all ungategorized options to the misc group + miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags) + AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...) + + // Make sure they are removed afterwards + defer func() { + AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs] + }() + } // Render out custom usage screen originalHelpPrinter(w, tmpl, helpData{data, AppHelpFlagGroups}) } else if tmpl == utils.CommandHelpTemplate { diff --git a/cmd/utils/flags_legacy.go b/cmd/utils/flags_legacy.go index ee288ce04f..a5520da9f4 100644 --- a/cmd/utils/flags_legacy.go +++ b/cmd/utils/flags_legacy.go @@ -34,7 +34,7 @@ var ShowDeprecated = cli.Command{ Description: "Show flags that have been deprecated and will soon be removed", } -var deprecatedFlags = []cli.Flag{ +var DeprecatedFlags = []cli.Flag{ LegacyTestnetFlag, LegacyLightServFlag, LegacyLightPeersFlag, @@ -157,7 +157,7 @@ func showDeprecated(*cli.Context) { fmt.Println("--------------------------------------------------------------------") fmt.Println() - for _, flag := range deprecatedFlags { + for _, flag := range DeprecatedFlags { fmt.Println(flag.String()) } }