@@ -28,7 +28,7 @@ import (
2828)
2929
3030var (
31- consoleFlags = []cli.Flag {utils .JSpathFlag , utils .ExecFlag , utils .PreloadJSFlag }
31+ consoleFlags = []cli.Flag {utils .JSpathFlag , utils .ExecFlag , utils .PreloadJSFlag , utils . HeaderFlag }
3232
3333 consoleCommand = & cli.Command {
3434 Action : localConsole ,
@@ -114,17 +114,13 @@ func localConsole(ctx *cli.Context) error {
114114// remoteConsole will connect to a remote geth instance, attaching a JavaScript
115115// console to it.
116116func remoteConsole (ctx * cli.Context ) error {
117- if ctx .Args ().Len () > 1 {
118- utils .Fatalf ("invalid command-line: too many arguments" )
119- }
120-
121117 endpoint := ctx .Args ().First ()
122118 if endpoint == "" {
123119 cfg := defaultNodeConfig ()
124120 utils .SetDataDir (ctx , & cfg )
125121 endpoint = cfg .IPCEndpoint ()
126122 }
127- client , err := dialRPC (endpoint )
123+ client , err := dialRPC (ctx , endpoint )
128124 if err != nil {
129125 utils .Fatalf ("Unable to attach to remote geth: %v" , err )
130126 }
@@ -167,13 +163,27 @@ geth --exec "%s" console`, b.String())
167163// dialRPC returns a RPC client which connects to the given endpoint.
168164// The check for empty endpoint implements the defaulting logic
169165// for "geth attach" with no argument.
170- func dialRPC (endpoint string ) (* rpc.Client , error ) {
166+ func dialRPC (ctx * cli. Context , endpoint string ) (* rpc.Client , error ) {
171167 if endpoint == "" {
172168 endpoint = node .DefaultIPCEndpoint (clientIdentifier )
173169 } else if strings .HasPrefix (endpoint , "rpc:" ) || strings .HasPrefix (endpoint , "ipc:" ) {
174170 // Backwards compatibility with geth < 1.5 which required
175171 // these prefixes.
176172 endpoint = endpoint [4 :]
177173 }
178- return rpc .Dial (endpoint )
174+ c , err := rpc .Dial (endpoint )
175+ if err != nil {
176+ return nil , err
177+ }
178+ if ctx .IsSet (utils .HeaderFlag .Name ) {
179+ for _ , keyValues := range ctx .StringSlice (utils .HeaderFlag .Name ) {
180+ keyValue := strings .Split (keyValues , ":" )
181+ if len (keyValue ) != 2 {
182+ return nil , fmt .Errorf ("invalid header value: %s" , keyValues )
183+ }
184+ k , v := keyValue [0 ], keyValue [1 ]
185+ c .SetHeader (k , v )
186+ }
187+ }
188+ return c , nil
179189}
0 commit comments