good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
a346aedb
Unverified
Commit
a346aedb
authored
7 years ago
by
Bas van Kervel
Browse files
Options
Downloads
Patches
Plain Diff
cmd/geth: reorganise help section for new cli flag handling
parent
ef25b826
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/geth/consolecmd.go
+0
-2
0 additions, 2 deletions
cmd/geth/consolecmd.go
cmd/geth/usage.go
+56
-0
56 additions, 0 deletions
cmd/geth/usage.go
cmd/utils/flags.go
+14
-10
14 additions, 10 deletions
cmd/utils/flags.go
with
70 additions
and
12 deletions
cmd/geth/consolecmd.go
+
0
−
2
View file @
a346aedb
...
...
@@ -30,9 +30,7 @@ import (
var
(
consoleFlags
=
[]
cli
.
Flag
{
utils
.
JSpathFlag
,
utils
.
ExecFlag
,
utils
.
PreloadJSFlag
}
)
var
(
consoleCommand
=
cli
.
Command
{
Action
:
utils
.
MigrateFlags
(
localConsole
),
Name
:
"console"
,
...
...
This diff is collapsed.
Click to expand it.
cmd/geth/usage.go
+
56
−
0
View file @
a346aedb
...
...
@@ -20,6 +20,7 @@ package main
import
(
"io"
"sort"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/internal/debug"
...
...
@@ -189,6 +190,39 @@ var AppHelpFlagGroups = []flagGroup{
},
}
// byCategory sorts an array of flagGroup by Name in the order
// defined in AppHelpFlagGroups.
type
byCategory
[]
flagGroup
func
(
a
byCategory
)
Len
()
int
{
return
len
(
a
)
}
func
(
a
byCategory
)
Swap
(
i
,
j
int
)
{
a
[
i
],
a
[
j
]
=
a
[
j
],
a
[
i
]
}
func
(
a
byCategory
)
Less
(
i
,
j
int
)
bool
{
iCat
,
jCat
:=
a
[
i
]
.
Name
,
a
[
j
]
.
Name
iIdx
,
jIdx
:=
len
(
AppHelpFlagGroups
),
len
(
AppHelpFlagGroups
)
// ensure non categorized flags come last
for
i
,
group
:=
range
AppHelpFlagGroups
{
if
iCat
==
group
.
Name
{
iIdx
=
i
}
if
jCat
==
group
.
Name
{
jIdx
=
i
}
}
return
iIdx
<
jIdx
}
func
flagCategory
(
flag
cli
.
Flag
)
string
{
for
_
,
category
:=
range
AppHelpFlagGroups
{
for
_
,
flg
:=
range
category
.
Flags
{
if
flg
.
GetName
()
==
flag
.
GetName
()
{
return
category
.
Name
}
}
}
return
"MISC"
}
func
init
()
{
// Override the default app help template
cli
.
AppHelpTemplate
=
AppHelpTemplate
...
...
@@ -198,6 +232,7 @@ func init() {
App
interface
{}
FlagGroups
[]
flagGroup
}
// Override the default app help printer, but only for the global app help
originalHelpPrinter
:=
cli
.
HelpPrinter
cli
.
HelpPrinter
=
func
(
w
io
.
Writer
,
tmpl
string
,
data
interface
{})
{
...
...
@@ -227,6 +262,27 @@ func init() {
}
// Render out custom usage screen
originalHelpPrinter
(
w
,
tmpl
,
helpData
{
data
,
AppHelpFlagGroups
})
}
else
if
tmpl
==
utils
.
CommandHelpTemplate
{
// Iterate over all command specific flags and categorize them
categorized
:=
make
(
map
[
string
][]
cli
.
Flag
)
for
_
,
flag
:=
range
data
.
(
cli
.
Command
)
.
Flags
{
if
_
,
ok
:=
categorized
[
flag
.
String
()];
!
ok
{
categorized
[
flagCategory
(
flag
)]
=
append
(
categorized
[
flagCategory
(
flag
)],
flag
)
}
}
// sort to get a stable ordering
sorted
:=
make
([]
flagGroup
,
0
,
len
(
categorized
))
for
cat
,
flgs
:=
range
categorized
{
sorted
=
append
(
sorted
,
flagGroup
{
cat
,
flgs
})
}
sort
.
Sort
(
byCategory
(
sorted
))
// add sorted array to data and render with default printer
originalHelpPrinter
(
w
,
tmpl
,
map
[
string
]
interface
{}{
"cmd"
:
data
,
"categorizedFlags"
:
sorted
,
})
}
else
{
originalHelpPrinter
(
w
,
tmpl
,
data
)
}
...
...
This diff is collapsed.
Click to expand it.
cmd/utils/flags.go
+
14
−
10
View file @
a346aedb
...
...
@@ -56,6 +56,19 @@ import (
"gopkg.in/urfave/cli.v1"
)
var
(
CommandHelpTemplate
=
`{{.cmd.Name}}{{if .cmd.Subcommands}} command{{end}}{{if .cmd.Flags}} [command options]{{end}} [arguments...]
{{if .cmd.Description}}{{.cmd.Description}}
{{end}}{{if .cmd.Subcommands}}
SUBCOMMANDS:
{{range .cmd.Subcommands}}{{.cmd.Name}}{{with .cmd.ShortName}}, {{.cmd}}{{end}}{{ "\t" }}{{.cmd.Usage}}
{{end}}{{end}}{{if .categorizedFlags}}
{{range $idx, $categorized := .categorizedFlags}}{{$categorized.Name}} OPTIONS:
{{range $categorized.Flags}}{{"\t"}}{{.}}
{{end}}
{{end}}{{end}}`
)
func
init
()
{
cli
.
AppHelpTemplate
=
`{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
...
...
@@ -70,16 +83,7 @@ GLOBAL OPTIONS:
{{end}}{{end}}
`
cli
.
CommandHelpTemplate
=
`{{.Name}}{{if .Subcommands}} command{{end}}{{if .Flags}} [command options]{{end}} [arguments...]
{{if .Description}}{{.Description}}
{{end}}{{if .Subcommands}}
SUBCOMMANDS:
{{range .Subcommands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}{{end}}{{if .Flags}}
OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
cli
.
CommandHelpTemplate
=
CommandHelpTemplate
}
// NewApp creates an app with sane defaults.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment