Skip to content

Commit 5b081ab

Browse files
authored
cmd/clef: change --rpcport to --http.port and update flags in docs (#21318)
1 parent 6ef4495 commit 5b081ab

File tree

10 files changed

+274
-136
lines changed

10 files changed

+274
-136
lines changed

cmd/abigen/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/ethereum/go-ethereum/cmd/utils"
3131
"github.com/ethereum/go-ethereum/common/compiler"
3232
"github.com/ethereum/go-ethereum/crypto"
33+
"github.com/ethereum/go-ethereum/internal/flags"
3334
"github.com/ethereum/go-ethereum/log"
3435
"gopkg.in/urfave/cli.v1"
3536
)
@@ -100,7 +101,7 @@ var (
100101
)
101102

102103
func init() {
103-
app = utils.NewApp(gitCommit, gitDate, "ethereum checkpoint helper tool")
104+
app = flags.NewApp(gitCommit, gitDate, "ethereum checkpoint helper tool")
104105
app.Flags = []cli.Flag{
105106
abiFlag,
106107
binFlag,
@@ -117,7 +118,7 @@ func init() {
117118
aliasFlag,
118119
}
119120
app.Action = utils.MigrateFlags(abigen)
120-
cli.CommandHelpTemplate = utils.OriginCommandHelpTemplate
121+
cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
121122
}
122123

123124
func abigen(c *cli.Context) error {

cmd/checkpoint-admin/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"fmt"
2323
"os"
2424

25-
"github.com/ethereum/go-ethereum/cmd/utils"
2625
"github.com/ethereum/go-ethereum/common/fdlimit"
26+
"github.com/ethereum/go-ethereum/internal/flags"
2727
"github.com/ethereum/go-ethereum/log"
2828
"gopkg.in/urfave/cli.v1"
2929
)
@@ -37,7 +37,7 @@ var (
3737
var app *cli.App
3838

3939
func init() {
40-
app = utils.NewApp(gitCommit, gitDate, "ethereum checkpoint helper tool")
40+
app = flags.NewApp(gitCommit, gitDate, "ethereum checkpoint helper tool")
4141
app.Commands = []cli.Command{
4242
commandStatus,
4343
commandDeploy,
@@ -48,7 +48,7 @@ func init() {
4848
oracleFlag,
4949
nodeURLFlag,
5050
}
51-
cli.CommandHelpTemplate = utils.OriginCommandHelpTemplate
51+
cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
5252
}
5353

5454
// Commonly used command line flags.

cmd/clef/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ GLOBAL OPTIONS:
3333
--lightkdf Reduce key-derivation RAM & CPU usage at some expense of KDF strength
3434
--nousb Disables monitoring for and managing USB hardware wallets
3535
--pcscdpath value Path to the smartcard daemon (pcscd) socket file (default: "/run/pcscd/pcscd.comm")
36-
--rpcaddr value HTTP-RPC server listening interface (default: "localhost")
37-
--rpcvhosts value Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
36+
--http.addr value HTTP-RPC server listening interface (default: "localhost")
37+
--http.vhosts value Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
3838
--ipcdisable Disable the IPC-RPC server
3939
--ipcpath Filename for IPC socket/pipe within the datadir (explicit paths escape it)
40-
--rpc Enable the HTTP-RPC server
41-
--rpcport value HTTP-RPC server listening port (default: 8550)
40+
--http Enable the HTTP-RPC server
41+
--http.port value HTTP-RPC server listening port (default: 8550)
4242
--signersecret value A file containing the (encrypted) master seed to encrypt Clef data, e.g. keystore credentials and ruleset hash
4343
--4bytedb-custom value File used for writing new 4byte-identifiers submitted via API (default: "./4byte-custom.json")
4444
--auditlog value File used to emit audit logs. Set to "" to disable (default: "audit.log")
@@ -113,7 +113,7 @@ Some snags and todos
113113

114114
### External API
115115

116-
Clef listens to HTTP requests on `rpcaddr`:`rpcport` (or to IPC on `ipcpath`), with the same JSON-RPC standard as Geth. The messages are expected to be [JSON-RPC 2.0 standard](https://www.jsonrpc.org/specification).
116+
Clef listens to HTTP requests on `http.addr`:`http.port` (or to IPC on `ipcpath`), with the same JSON-RPC standard as Geth. The messages are expected to be [JSON-RPC 2.0 standard](https://www.jsonrpc.org/specification).
117117

118118
Some of these calls can require user interaction. Clients must be aware that responses may be delayed significantly or may never be received if a user decides to ignore the confirmation request.
119119

cmd/clef/main.go

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"os/user"
3333
"path/filepath"
3434
"runtime"
35+
"sort"
3536
"strings"
3637
"time"
3738

@@ -43,6 +44,7 @@ import (
4344
"github.com/ethereum/go-ethereum/core/types"
4445
"github.com/ethereum/go-ethereum/crypto"
4546
"github.com/ethereum/go-ethereum/internal/ethapi"
47+
"github.com/ethereum/go-ethereum/internal/flags"
4648
"github.com/ethereum/go-ethereum/log"
4749
"github.com/ethereum/go-ethereum/node"
4850
"github.com/ethereum/go-ethereum/params"
@@ -52,6 +54,7 @@ import (
5254
"github.com/ethereum/go-ethereum/signer/fourbyte"
5355
"github.com/ethereum/go-ethereum/signer/rules"
5456
"github.com/ethereum/go-ethereum/signer/storage"
57+
5558
colorable "github.com/mattn/go-colorable"
5659
"github.com/mattn/go-isatty"
5760
"gopkg.in/urfave/cli.v1"
@@ -101,10 +104,15 @@ var (
101104
Usage: "Chain id to use for signing (1=mainnet, 3=Ropsten, 4=Rinkeby, 5=Goerli)",
102105
}
103106
rpcPortFlag = cli.IntFlag{
104-
Name: "rpcport",
107+
Name: "http.port",
105108
Usage: "HTTP-RPC server listening port",
106109
Value: node.DefaultHTTPPort + 5,
107110
}
111+
legacyRPCPortFlag = cli.IntFlag{
112+
Name: "rpcport",
113+
Usage: "HTTP-RPC server listening port (Deprecated, please use --http.port).",
114+
Value: node.DefaultHTTPPort + 5,
115+
}
108116
signerSecretFlag = cli.StringFlag{
109117
Name: "signersecret",
110118
Usage: "A file containing the (encrypted) master seed to encrypt Clef data, e.g. keystore credentials and ruleset hash",
@@ -215,6 +223,42 @@ The gendoc generates example structures of the json-rpc communication types.
215223
`}
216224
)
217225

226+
// AppHelpFlagGroups is the application flags, grouped by functionality.
227+
var AppHelpFlagGroups = []flags.FlagGroup{
228+
{
229+
Name: "FLAGS",
230+
Flags: []cli.Flag{
231+
logLevelFlag,
232+
keystoreFlag,
233+
configdirFlag,
234+
chainIdFlag,
235+
utils.LightKDFFlag,
236+
utils.NoUSBFlag,
237+
utils.SmartCardDaemonPathFlag,
238+
utils.HTTPListenAddrFlag,
239+
utils.HTTPVirtualHostsFlag,
240+
utils.IPCDisabledFlag,
241+
utils.IPCPathFlag,
242+
utils.HTTPEnabledFlag,
243+
rpcPortFlag,
244+
signerSecretFlag,
245+
customDBFlag,
246+
auditLogFlag,
247+
ruleFlag,
248+
stdiouiFlag,
249+
testFlag,
250+
advancedMode,
251+
acceptFlag,
252+
},
253+
},
254+
{
255+
Name: "ALIASED (deprecated)",
256+
Flags: []cli.Flag{
257+
legacyRPCPortFlag,
258+
},
259+
},
260+
}
261+
218262
func init() {
219263
app.Name = "Clef"
220264
app.Usage = "Manage Ethereum account operations"
@@ -240,6 +284,7 @@ func init() {
240284
testFlag,
241285
advancedMode,
242286
acceptFlag,
287+
legacyRPCPortFlag,
243288
}
244289
app.Action = signer
245290
app.Commands = []cli.Command{initCommand,
@@ -248,7 +293,41 @@ func init() {
248293
delCredentialCommand,
249294
newAccountCommand,
250295
gendocCommand}
251-
cli.CommandHelpTemplate = utils.OriginCommandHelpTemplate
296+
cli.CommandHelpTemplate = flags.CommandHelpTemplate
297+
// Override the default app help template
298+
cli.AppHelpTemplate = flags.ClefAppHelpTemplate
299+
300+
// Override the default app help printer, but only for the global app help
301+
originalHelpPrinter := cli.HelpPrinter
302+
cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
303+
if tmpl == flags.ClefAppHelpTemplate {
304+
// Render out custom usage screen
305+
originalHelpPrinter(w, tmpl, flags.HelpData{App: data, FlagGroups: AppHelpFlagGroups})
306+
} else if tmpl == flags.CommandHelpTemplate {
307+
// Iterate over all command specific flags and categorize them
308+
categorized := make(map[string][]cli.Flag)
309+
for _, flag := range data.(cli.Command).Flags {
310+
if _, ok := categorized[flag.String()]; !ok {
311+
categorized[flags.FlagCategory(flag, AppHelpFlagGroups)] = append(categorized[flags.FlagCategory(flag, AppHelpFlagGroups)], flag)
312+
}
313+
}
314+
315+
// sort to get a stable ordering
316+
sorted := make([]flags.FlagGroup, 0, len(categorized))
317+
for cat, flgs := range categorized {
318+
sorted = append(sorted, flags.FlagGroup{Name: cat, Flags: flgs})
319+
}
320+
sort.Sort(flags.ByCategory(sorted))
321+
322+
// add sorted array to data and render with default printer
323+
originalHelpPrinter(w, tmpl, map[string]interface{}{
324+
"cmd": data,
325+
"categorizedFlags": sorted,
326+
})
327+
} else {
328+
originalHelpPrinter(w, tmpl, data)
329+
}
330+
}
252331
}
253332

254333
func main() {
@@ -597,8 +676,17 @@ func signer(c *cli.Context) error {
597676
}
598677
handler := node.NewHTTPHandlerStack(srv, cors, vhosts)
599678

679+
// set port
680+
port := c.Int(rpcPortFlag.Name)
681+
if c.GlobalIsSet(legacyRPCPortFlag.Name) {
682+
if !c.GlobalIsSet(rpcPortFlag.Name) {
683+
port = c.Int(legacyRPCPortFlag.Name)
684+
}
685+
log.Warn("The flag --rpcport is deprecated and will be removed in the future, please use --http.port")
686+
}
687+
600688
// start http server
601-
httpEndpoint := fmt.Sprintf("%s:%d", c.GlobalString(utils.HTTPListenAddrFlag.Name), c.Int(rpcPortFlag.Name))
689+
httpEndpoint := fmt.Sprintf("%s:%d", c.GlobalString(utils.HTTPListenAddrFlag.Name), port)
602690
httpServer, addr, err := node.StartHTTPEndpoint(httpEndpoint, rpc.DefaultHTTPTimeouts, handler)
603691
if err != nil {
604692
utils.Fatalf("Could not start RPC api: %v", err)

cmd/ethkey/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222

23-
"github.com/ethereum/go-ethereum/cmd/utils"
23+
"github.com/ethereum/go-ethereum/internal/flags"
2424
"gopkg.in/urfave/cli.v1"
2525
)
2626

@@ -35,15 +35,15 @@ var gitDate = ""
3535
var app *cli.App
3636

3737
func init() {
38-
app = utils.NewApp(gitCommit, gitDate, "an Ethereum key manager")
38+
app = flags.NewApp(gitCommit, gitDate, "an Ethereum key manager")
3939
app.Commands = []cli.Command{
4040
commandGenerate,
4141
commandInspect,
4242
commandChangePassphrase,
4343
commandSignMessage,
4444
commandVerifyMessage,
4545
}
46-
cli.CommandHelpTemplate = utils.OriginCommandHelpTemplate
46+
cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
4747
}
4848

4949
// Commonly used command line flags.

cmd/evm/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ import (
2424

2525
"github.com/ethereum/go-ethereum/cmd/evm/internal/t8ntool"
2626
"github.com/ethereum/go-ethereum/cmd/utils"
27+
"github.com/ethereum/go-ethereum/internal/flags"
2728
"gopkg.in/urfave/cli.v1"
2829
)
2930

3031
var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
3132
var gitDate = ""
3233

3334
var (
34-
app = utils.NewApp(gitCommit, gitDate, "the evm command line interface")
35+
app = flags.NewApp(gitCommit, gitDate, "the evm command line interface")
3536

3637
DebugFlag = cli.BoolFlag{
3738
Name: "debug",
@@ -180,7 +181,7 @@ func init() {
180181
stateTestCommand,
181182
stateTransitionCommand,
182183
}
183-
cli.CommandHelpTemplate = utils.OriginCommandHelpTemplate
184+
cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
184185
}
185186

186187
func main() {

cmd/geth/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/ethereum/go-ethereum/eth/downloader"
3737
"github.com/ethereum/go-ethereum/ethclient"
3838
"github.com/ethereum/go-ethereum/internal/debug"
39+
"github.com/ethereum/go-ethereum/internal/flags"
3940
"github.com/ethereum/go-ethereum/les"
4041
"github.com/ethereum/go-ethereum/log"
4142
"github.com/ethereum/go-ethereum/metrics"
@@ -53,7 +54,7 @@ var (
5354
gitCommit = ""
5455
gitDate = ""
5556
// The app that holds all commands and flags.
56-
app = utils.NewApp(gitCommit, gitDate, "the go-ethereum command line interface")
57+
app = flags.NewApp(gitCommit, gitDate, "the go-ethereum command line interface")
5758
// flags that configure the node
5859
nodeFlags = []cli.Flag{
5960
utils.IdentityFlag,

0 commit comments

Comments
 (0)