flags.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. // Package utils contains internal helper functions for go-ethereum commands.
  17. package utils
  18. import (
  19. "crypto/ecdsa"
  20. "fmt"
  21. "io/ioutil"
  22. "math/big"
  23. "os"
  24. "path/filepath"
  25. "runtime"
  26. "strconv"
  27. "strings"
  28. "github.com/ethereum/go-ethereum/accounts"
  29. "github.com/ethereum/go-ethereum/accounts/keystore"
  30. "github.com/ethereum/go-ethereum/common"
  31. "github.com/ethereum/go-ethereum/consensus/ethash"
  32. "github.com/ethereum/go-ethereum/core"
  33. "github.com/ethereum/go-ethereum/core/state"
  34. "github.com/ethereum/go-ethereum/core/vm"
  35. "github.com/ethereum/go-ethereum/crypto"
  36. "github.com/ethereum/go-ethereum/eth"
  37. "github.com/ethereum/go-ethereum/eth/downloader"
  38. "github.com/ethereum/go-ethereum/eth/gasprice"
  39. "github.com/ethereum/go-ethereum/ethdb"
  40. "github.com/ethereum/go-ethereum/ethstats"
  41. "github.com/ethereum/go-ethereum/event"
  42. "github.com/ethereum/go-ethereum/les"
  43. "github.com/ethereum/go-ethereum/log"
  44. "github.com/ethereum/go-ethereum/metrics"
  45. "github.com/ethereum/go-ethereum/node"
  46. "github.com/ethereum/go-ethereum/p2p"
  47. "github.com/ethereum/go-ethereum/p2p/discover"
  48. "github.com/ethereum/go-ethereum/p2p/discv5"
  49. "github.com/ethereum/go-ethereum/p2p/nat"
  50. "github.com/ethereum/go-ethereum/p2p/netutil"
  51. "github.com/ethereum/go-ethereum/params"
  52. whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
  53. "gopkg.in/urfave/cli.v1"
  54. )
  55. var (
  56. CommandHelpTemplate = `{{.cmd.Name}}{{if .cmd.Subcommands}} command{{end}}{{if .cmd.Flags}} [command options]{{end}} [arguments...]
  57. {{if .cmd.Description}}{{.cmd.Description}}
  58. {{end}}{{if .cmd.Subcommands}}
  59. SUBCOMMANDS:
  60. {{range .cmd.Subcommands}}{{.cmd.Name}}{{with .cmd.ShortName}}, {{.cmd}}{{end}}{{ "\t" }}{{.cmd.Usage}}
  61. {{end}}{{end}}{{if .categorizedFlags}}
  62. {{range $idx, $categorized := .categorizedFlags}}{{$categorized.Name}} OPTIONS:
  63. {{range $categorized.Flags}}{{"\t"}}{{.}}
  64. {{end}}
  65. {{end}}{{end}}`
  66. )
  67. func init() {
  68. cli.AppHelpTemplate = `{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
  69. VERSION:
  70. {{.Version}}
  71. COMMANDS:
  72. {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
  73. {{end}}{{if .Flags}}
  74. GLOBAL OPTIONS:
  75. {{range .Flags}}{{.}}
  76. {{end}}{{end}}
  77. `
  78. cli.CommandHelpTemplate = CommandHelpTemplate
  79. }
  80. // NewApp creates an app with sane defaults.
  81. func NewApp(gitCommit, usage string) *cli.App {
  82. app := cli.NewApp()
  83. app.Name = filepath.Base(os.Args[0])
  84. app.Author = ""
  85. //app.Authors = nil
  86. app.Email = ""
  87. app.Version = params.Version
  88. if gitCommit != "" {
  89. app.Version += "-" + gitCommit[:8]
  90. }
  91. app.Usage = usage
  92. return app
  93. }
  94. // These are all the command line flags we support.
  95. // If you add to this list, please remember to include the
  96. // flag in the appropriate command definition.
  97. //
  98. // The flags are defined here so their names and help texts
  99. // are the same for all commands.
  100. var (
  101. // General settings
  102. DataDirFlag = DirectoryFlag{
  103. Name: "datadir",
  104. Usage: "Data directory for the databases and keystore",
  105. Value: DirectoryString{node.DefaultDataDir()},
  106. }
  107. KeyStoreDirFlag = DirectoryFlag{
  108. Name: "keystore",
  109. Usage: "Directory for the keystore (default = inside the datadir)",
  110. }
  111. NoUSBFlag = cli.BoolFlag{
  112. Name: "nousb",
  113. Usage: "Disables monitoring for and managine USB hardware wallets",
  114. }
  115. EthashCacheDirFlag = DirectoryFlag{
  116. Name: "ethash.cachedir",
  117. Usage: "Directory to store the ethash verification caches (default = inside the datadir)",
  118. }
  119. EthashCachesInMemoryFlag = cli.IntFlag{
  120. Name: "ethash.cachesinmem",
  121. Usage: "Number of recent ethash caches to keep in memory (16MB each)",
  122. Value: eth.DefaultConfig.EthashCachesInMem,
  123. }
  124. EthashCachesOnDiskFlag = cli.IntFlag{
  125. Name: "ethash.cachesondisk",
  126. Usage: "Number of recent ethash caches to keep on disk (16MB each)",
  127. Value: eth.DefaultConfig.EthashCachesOnDisk,
  128. }
  129. EthashDatasetDirFlag = DirectoryFlag{
  130. Name: "ethash.dagdir",
  131. Usage: "Directory to store the ethash mining DAGs (default = inside home folder)",
  132. Value: DirectoryString{eth.DefaultConfig.EthashDatasetDir},
  133. }
  134. EthashDatasetsInMemoryFlag = cli.IntFlag{
  135. Name: "ethash.dagsinmem",
  136. Usage: "Number of recent ethash mining DAGs to keep in memory (1+GB each)",
  137. Value: eth.DefaultConfig.EthashDatasetsInMem,
  138. }
  139. EthashDatasetsOnDiskFlag = cli.IntFlag{
  140. Name: "ethash.dagsondisk",
  141. Usage: "Number of recent ethash mining DAGs to keep on disk (1+GB each)",
  142. Value: eth.DefaultConfig.EthashDatasetsOnDisk,
  143. }
  144. NetworkIdFlag = cli.Uint64Flag{
  145. Name: "networkid",
  146. Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby)",
  147. Value: eth.DefaultConfig.NetworkId,
  148. }
  149. TestnetFlag = cli.BoolFlag{
  150. Name: "testnet",
  151. Usage: "Ropsten network: pre-configured proof-of-work test network",
  152. }
  153. RinkebyFlag = cli.BoolFlag{
  154. Name: "rinkeby",
  155. Usage: "Rinkeby network: pre-configured proof-of-authority test network",
  156. }
  157. DevModeFlag = cli.BoolFlag{
  158. Name: "dev",
  159. Usage: "Developer mode: pre-configured private network with several debugging flags",
  160. }
  161. IdentityFlag = cli.StringFlag{
  162. Name: "identity",
  163. Usage: "Custom node name",
  164. }
  165. DocRootFlag = DirectoryFlag{
  166. Name: "docroot",
  167. Usage: "Document Root for HTTPClient file scheme",
  168. Value: DirectoryString{homeDir()},
  169. }
  170. FastSyncFlag = cli.BoolFlag{
  171. Name: "fast",
  172. Usage: "Enable fast syncing through state downloads",
  173. }
  174. LightModeFlag = cli.BoolFlag{
  175. Name: "light",
  176. Usage: "Enable light client mode",
  177. }
  178. defaultSyncMode = eth.DefaultConfig.SyncMode
  179. SyncModeFlag = TextMarshalerFlag{
  180. Name: "syncmode",
  181. Usage: `Blockchain sync mode ("fast", "full", or "light")`,
  182. Value: &defaultSyncMode,
  183. }
  184. LightServFlag = cli.IntFlag{
  185. Name: "lightserv",
  186. Usage: "Maximum percentage of time allowed for serving LES requests (0-90)",
  187. Value: 0,
  188. }
  189. LightPeersFlag = cli.IntFlag{
  190. Name: "lightpeers",
  191. Usage: "Maximum number of LES client peers",
  192. Value: 20,
  193. }
  194. LightKDFFlag = cli.BoolFlag{
  195. Name: "lightkdf",
  196. Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
  197. }
  198. // Performance tuning settings
  199. CacheFlag = cli.IntFlag{
  200. Name: "cache",
  201. Usage: "Megabytes of memory allocated to internal caching (min 16MB / database forced)",
  202. Value: 128,
  203. }
  204. TrieCacheGenFlag = cli.IntFlag{
  205. Name: "trie-cache-gens",
  206. Usage: "Number of trie node generations to keep in memory",
  207. Value: int(state.MaxTrieCacheGen),
  208. }
  209. // Miner settings
  210. MiningEnabledFlag = cli.BoolFlag{
  211. Name: "mine",
  212. Usage: "Enable mining",
  213. }
  214. MinerThreadsFlag = cli.IntFlag{
  215. Name: "minerthreads",
  216. Usage: "Number of CPU threads to use for mining",
  217. Value: runtime.NumCPU(),
  218. }
  219. TargetGasLimitFlag = cli.Uint64Flag{
  220. Name: "targetgaslimit",
  221. Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
  222. Value: params.GenesisGasLimit.Uint64(),
  223. }
  224. EtherbaseFlag = cli.StringFlag{
  225. Name: "etherbase",
  226. Usage: "Public address for block mining rewards (default = first account created)",
  227. Value: "0",
  228. }
  229. GasPriceFlag = BigFlag{
  230. Name: "gasprice",
  231. Usage: "Minimal gas price to accept for mining a transactions",
  232. Value: eth.DefaultConfig.GasPrice,
  233. }
  234. ExtraDataFlag = cli.StringFlag{
  235. Name: "extradata",
  236. Usage: "Block extra data set by the miner (default = client version)",
  237. }
  238. // Account settings
  239. UnlockedAccountFlag = cli.StringFlag{
  240. Name: "unlock",
  241. Usage: "Comma separated list of accounts to unlock",
  242. Value: "",
  243. }
  244. PasswordFileFlag = cli.StringFlag{
  245. Name: "password",
  246. Usage: "Password file to use for non-inteactive password input",
  247. Value: "",
  248. }
  249. VMEnableDebugFlag = cli.BoolFlag{
  250. Name: "vmdebug",
  251. Usage: "Record information useful for VM and contract debugging",
  252. }
  253. // Logging and debug settings
  254. EthStatsURLFlag = cli.StringFlag{
  255. Name: "ethstats",
  256. Usage: "Reporting URL of a ethstats service (nodename:secret@host:port)",
  257. }
  258. MetricsEnabledFlag = cli.BoolFlag{
  259. Name: metrics.MetricsEnabledFlag,
  260. Usage: "Enable metrics collection and reporting",
  261. }
  262. FakePoWFlag = cli.BoolFlag{
  263. Name: "fakepow",
  264. Usage: "Disables proof-of-work verification",
  265. }
  266. NoCompactionFlag = cli.BoolFlag{
  267. Name: "nocompaction",
  268. Usage: "Disables db compaction after import",
  269. }
  270. // RPC settings
  271. RPCEnabledFlag = cli.BoolFlag{
  272. Name: "rpc",
  273. Usage: "Enable the HTTP-RPC server",
  274. }
  275. RPCListenAddrFlag = cli.StringFlag{
  276. Name: "rpcaddr",
  277. Usage: "HTTP-RPC server listening interface",
  278. Value: node.DefaultHTTPHost,
  279. }
  280. RPCPortFlag = cli.IntFlag{
  281. Name: "rpcport",
  282. Usage: "HTTP-RPC server listening port",
  283. Value: node.DefaultHTTPPort,
  284. }
  285. RPCCORSDomainFlag = cli.StringFlag{
  286. Name: "rpccorsdomain",
  287. Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
  288. Value: "",
  289. }
  290. RPCApiFlag = cli.StringFlag{
  291. Name: "rpcapi",
  292. Usage: "API's offered over the HTTP-RPC interface",
  293. Value: "",
  294. }
  295. IPCDisabledFlag = cli.BoolFlag{
  296. Name: "ipcdisable",
  297. Usage: "Disable the IPC-RPC server",
  298. }
  299. IPCPathFlag = DirectoryFlag{
  300. Name: "ipcpath",
  301. Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
  302. }
  303. WSEnabledFlag = cli.BoolFlag{
  304. Name: "ws",
  305. Usage: "Enable the WS-RPC server",
  306. }
  307. WSListenAddrFlag = cli.StringFlag{
  308. Name: "wsaddr",
  309. Usage: "WS-RPC server listening interface",
  310. Value: node.DefaultWSHost,
  311. }
  312. WSPortFlag = cli.IntFlag{
  313. Name: "wsport",
  314. Usage: "WS-RPC server listening port",
  315. Value: node.DefaultWSPort,
  316. }
  317. WSApiFlag = cli.StringFlag{
  318. Name: "wsapi",
  319. Usage: "API's offered over the WS-RPC interface",
  320. Value: "",
  321. }
  322. WSAllowedOriginsFlag = cli.StringFlag{
  323. Name: "wsorigins",
  324. Usage: "Origins from which to accept websockets requests",
  325. Value: "",
  326. }
  327. ExecFlag = cli.StringFlag{
  328. Name: "exec",
  329. Usage: "Execute JavaScript statement",
  330. }
  331. PreloadJSFlag = cli.StringFlag{
  332. Name: "preload",
  333. Usage: "Comma separated list of JavaScript files to preload into the console",
  334. }
  335. // Network Settings
  336. MaxPeersFlag = cli.IntFlag{
  337. Name: "maxpeers",
  338. Usage: "Maximum number of network peers (network disabled if set to 0)",
  339. Value: 25,
  340. }
  341. MaxPendingPeersFlag = cli.IntFlag{
  342. Name: "maxpendpeers",
  343. Usage: "Maximum number of pending connection attempts (defaults used if set to 0)",
  344. Value: 0,
  345. }
  346. ListenPortFlag = cli.IntFlag{
  347. Name: "port",
  348. Usage: "Network listening port",
  349. Value: 30303,
  350. }
  351. BootnodesFlag = cli.StringFlag{
  352. Name: "bootnodes",
  353. Usage: "Comma separated enode URLs for P2P discovery bootstrap (set v4+v5 instead for light servers)",
  354. Value: "",
  355. }
  356. BootnodesV4Flag = cli.StringFlag{
  357. Name: "bootnodesv4",
  358. Usage: "Comma separated enode URLs for P2P v4 discovery bootstrap (light server, full nodes)",
  359. Value: "",
  360. }
  361. BootnodesV5Flag = cli.StringFlag{
  362. Name: "bootnodesv5",
  363. Usage: "Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes)",
  364. Value: "",
  365. }
  366. NodeKeyFileFlag = cli.StringFlag{
  367. Name: "nodekey",
  368. Usage: "P2P node key file",
  369. }
  370. NodeKeyHexFlag = cli.StringFlag{
  371. Name: "nodekeyhex",
  372. Usage: "P2P node key as hex (for testing)",
  373. }
  374. NATFlag = cli.StringFlag{
  375. Name: "nat",
  376. Usage: "NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP>)",
  377. Value: "any",
  378. }
  379. NoDiscoverFlag = cli.BoolFlag{
  380. Name: "nodiscover",
  381. Usage: "Disables the peer discovery mechanism (manual peer addition)",
  382. }
  383. DiscoveryV5Flag = cli.BoolFlag{
  384. Name: "v5disc",
  385. Usage: "Enables the experimental RLPx V5 (Topic Discovery) mechanism",
  386. }
  387. NetrestrictFlag = cli.StringFlag{
  388. Name: "netrestrict",
  389. Usage: "Restricts network communication to the given IP networks (CIDR masks)",
  390. }
  391. WhisperEnabledFlag = cli.BoolFlag{
  392. Name: "shh",
  393. Usage: "Enable Whisper",
  394. }
  395. // ATM the url is left to the user and deployment to
  396. JSpathFlag = cli.StringFlag{
  397. Name: "jspath",
  398. Usage: "JavaScript root path for `loadScript`",
  399. Value: ".",
  400. }
  401. // Gas price oracle settings
  402. GpoBlocksFlag = cli.IntFlag{
  403. Name: "gpoblocks",
  404. Usage: "Number of recent blocks to check for gas prices",
  405. Value: eth.DefaultConfig.GPO.Blocks,
  406. }
  407. GpoPercentileFlag = cli.IntFlag{
  408. Name: "gpopercentile",
  409. Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
  410. Value: eth.DefaultConfig.GPO.Percentile,
  411. }
  412. )
  413. // MakeDataDir retrieves the currently requested data directory, terminating
  414. // if none (or the empty string) is specified. If the node is starting a testnet,
  415. // the a subdirectory of the specified datadir will be used.
  416. func MakeDataDir(ctx *cli.Context) string {
  417. if path := ctx.GlobalString(DataDirFlag.Name); path != "" {
  418. if ctx.GlobalBool(TestnetFlag.Name) {
  419. return filepath.Join(path, "testnet")
  420. }
  421. if ctx.GlobalBool(RinkebyFlag.Name) {
  422. return filepath.Join(path, "rinkeby")
  423. }
  424. return path
  425. }
  426. Fatalf("Cannot determine default data directory, please set manually (--datadir)")
  427. return ""
  428. }
  429. // setNodeKey creates a node key from set command line flags, either loading it
  430. // from a file or as a specified hex value. If neither flags were provided, this
  431. // method returns nil and an emphemeral key is to be generated.
  432. func setNodeKey(ctx *cli.Context, cfg *p2p.Config) {
  433. var (
  434. hex = ctx.GlobalString(NodeKeyHexFlag.Name)
  435. file = ctx.GlobalString(NodeKeyFileFlag.Name)
  436. key *ecdsa.PrivateKey
  437. err error
  438. )
  439. switch {
  440. case file != "" && hex != "":
  441. Fatalf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name)
  442. case file != "":
  443. if key, err = crypto.LoadECDSA(file); err != nil {
  444. Fatalf("Option %q: %v", NodeKeyFileFlag.Name, err)
  445. }
  446. cfg.PrivateKey = key
  447. case hex != "":
  448. if key, err = crypto.HexToECDSA(hex); err != nil {
  449. Fatalf("Option %q: %v", NodeKeyHexFlag.Name, err)
  450. }
  451. cfg.PrivateKey = key
  452. }
  453. }
  454. // setNodeUserIdent creates the user identifier from CLI flags.
  455. func setNodeUserIdent(ctx *cli.Context, cfg *node.Config) {
  456. if identity := ctx.GlobalString(IdentityFlag.Name); len(identity) > 0 {
  457. cfg.UserIdent = identity
  458. }
  459. }
  460. // setBootstrapNodes creates a list of bootstrap nodes from the command line
  461. // flags, reverting to pre-configured ones if none have been specified.
  462. func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
  463. urls := params.MainnetBootnodes
  464. switch {
  465. case ctx.GlobalIsSet(BootnodesFlag.Name) || ctx.GlobalIsSet(BootnodesV4Flag.Name):
  466. if ctx.GlobalIsSet(BootnodesV4Flag.Name) {
  467. urls = strings.Split(ctx.GlobalString(BootnodesV4Flag.Name), ",")
  468. } else {
  469. urls = strings.Split(ctx.GlobalString(BootnodesFlag.Name), ",")
  470. }
  471. case ctx.GlobalBool(TestnetFlag.Name):
  472. urls = params.TestnetBootnodes
  473. case ctx.GlobalBool(RinkebyFlag.Name):
  474. urls = params.RinkebyBootnodes
  475. }
  476. cfg.BootstrapNodes = make([]*discover.Node, 0, len(urls))
  477. for _, url := range urls {
  478. node, err := discover.ParseNode(url)
  479. if err != nil {
  480. log.Error("Bootstrap URL invalid", "enode", url, "err", err)
  481. continue
  482. }
  483. cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
  484. }
  485. }
  486. // setBootstrapNodesV5 creates a list of bootstrap nodes from the command line
  487. // flags, reverting to pre-configured ones if none have been specified.
  488. func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
  489. urls := params.DiscoveryV5Bootnodes
  490. switch {
  491. case ctx.GlobalIsSet(BootnodesFlag.Name) || ctx.GlobalIsSet(BootnodesV5Flag.Name):
  492. if ctx.GlobalIsSet(BootnodesV5Flag.Name) {
  493. urls = strings.Split(ctx.GlobalString(BootnodesV5Flag.Name), ",")
  494. } else {
  495. urls = strings.Split(ctx.GlobalString(BootnodesFlag.Name), ",")
  496. }
  497. case ctx.GlobalBool(RinkebyFlag.Name):
  498. urls = params.RinkebyV5Bootnodes
  499. case cfg.BootstrapNodesV5 != nil:
  500. return // already set, don't apply defaults.
  501. }
  502. cfg.BootstrapNodesV5 = make([]*discv5.Node, 0, len(urls))
  503. for _, url := range urls {
  504. node, err := discv5.ParseNode(url)
  505. if err != nil {
  506. log.Error("Bootstrap URL invalid", "enode", url, "err", err)
  507. continue
  508. }
  509. cfg.BootstrapNodesV5 = append(cfg.BootstrapNodesV5, node)
  510. }
  511. }
  512. // setListenAddress creates a TCP listening address string from set command
  513. // line flags.
  514. func setListenAddress(ctx *cli.Context, cfg *p2p.Config) {
  515. if ctx.GlobalIsSet(ListenPortFlag.Name) {
  516. cfg.ListenAddr = fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortFlag.Name))
  517. }
  518. }
  519. // setDiscoveryV5Address creates a UDP listening address string from set command
  520. // line flags for the V5 discovery protocol.
  521. func setDiscoveryV5Address(ctx *cli.Context, cfg *p2p.Config) {
  522. if ctx.GlobalIsSet(ListenPortFlag.Name) {
  523. cfg.DiscoveryV5Addr = fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortFlag.Name)+1)
  524. }
  525. }
  526. // setNAT creates a port mapper from command line flags.
  527. func setNAT(ctx *cli.Context, cfg *p2p.Config) {
  528. if ctx.GlobalIsSet(NATFlag.Name) {
  529. natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
  530. if err != nil {
  531. Fatalf("Option %s: %v", NATFlag.Name, err)
  532. }
  533. cfg.NAT = natif
  534. }
  535. }
  536. // splitAndTrim splits input separated by a comma
  537. // and trims excessive white space from the substrings.
  538. func splitAndTrim(input string) []string {
  539. result := strings.Split(input, ",")
  540. for i, r := range result {
  541. result[i] = strings.TrimSpace(r)
  542. }
  543. return result
  544. }
  545. // setHTTP creates the HTTP RPC listener interface string from the set
  546. // command line flags, returning empty if the HTTP endpoint is disabled.
  547. func setHTTP(ctx *cli.Context, cfg *node.Config) {
  548. if ctx.GlobalBool(RPCEnabledFlag.Name) && cfg.HTTPHost == "" {
  549. cfg.HTTPHost = "127.0.0.1"
  550. if ctx.GlobalIsSet(RPCListenAddrFlag.Name) {
  551. cfg.HTTPHost = ctx.GlobalString(RPCListenAddrFlag.Name)
  552. }
  553. }
  554. if ctx.GlobalIsSet(RPCPortFlag.Name) {
  555. cfg.HTTPPort = ctx.GlobalInt(RPCPortFlag.Name)
  556. }
  557. if ctx.GlobalIsSet(RPCCORSDomainFlag.Name) {
  558. cfg.HTTPCors = splitAndTrim(ctx.GlobalString(RPCCORSDomainFlag.Name))
  559. }
  560. if ctx.GlobalIsSet(RPCApiFlag.Name) {
  561. cfg.HTTPModules = splitAndTrim(ctx.GlobalString(RPCApiFlag.Name))
  562. }
  563. }
  564. // setWS creates the WebSocket RPC listener interface string from the set
  565. // command line flags, returning empty if the HTTP endpoint is disabled.
  566. func setWS(ctx *cli.Context, cfg *node.Config) {
  567. if ctx.GlobalBool(WSEnabledFlag.Name) && cfg.WSHost == "" {
  568. cfg.WSHost = "127.0.0.1"
  569. if ctx.GlobalIsSet(WSListenAddrFlag.Name) {
  570. cfg.WSHost = ctx.GlobalString(WSListenAddrFlag.Name)
  571. }
  572. }
  573. if ctx.GlobalIsSet(WSPortFlag.Name) {
  574. cfg.WSPort = ctx.GlobalInt(WSPortFlag.Name)
  575. }
  576. if ctx.GlobalIsSet(WSAllowedOriginsFlag.Name) {
  577. cfg.WSOrigins = splitAndTrim(ctx.GlobalString(WSAllowedOriginsFlag.Name))
  578. }
  579. if ctx.GlobalIsSet(WSApiFlag.Name) {
  580. cfg.WSModules = splitAndTrim(ctx.GlobalString(WSApiFlag.Name))
  581. }
  582. }
  583. // setIPC creates an IPC path configuration from the set command line flags,
  584. // returning an empty string if IPC was explicitly disabled, or the set path.
  585. func setIPC(ctx *cli.Context, cfg *node.Config) {
  586. checkExclusive(ctx, IPCDisabledFlag, IPCPathFlag)
  587. switch {
  588. case ctx.GlobalBool(IPCDisabledFlag.Name):
  589. cfg.IPCPath = ""
  590. case ctx.GlobalIsSet(IPCPathFlag.Name):
  591. cfg.IPCPath = ctx.GlobalString(IPCPathFlag.Name)
  592. }
  593. }
  594. // makeDatabaseHandles raises out the number of allowed file handles per process
  595. // for Geth and returns half of the allowance to assign to the database.
  596. func makeDatabaseHandles() int {
  597. if err := raiseFdLimit(2048); err != nil {
  598. Fatalf("Failed to raise file descriptor allowance: %v", err)
  599. }
  600. limit, err := getFdLimit()
  601. if err != nil {
  602. Fatalf("Failed to retrieve file descriptor allowance: %v", err)
  603. }
  604. if limit > 2048 { // cap database file descriptors even if more is available
  605. limit = 2048
  606. }
  607. return limit / 2 // Leave half for networking and other stuff
  608. }
  609. // MakeAddress converts an account specified directly as a hex encoded string or
  610. // a key index in the key store to an internal account representation.
  611. func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error) {
  612. // If the specified account is a valid address, return it
  613. if common.IsHexAddress(account) {
  614. return accounts.Account{Address: common.HexToAddress(account)}, nil
  615. }
  616. // Otherwise try to interpret the account as a keystore index
  617. index, err := strconv.Atoi(account)
  618. if err != nil || index < 0 {
  619. return accounts.Account{}, fmt.Errorf("invalid account address or index %q", account)
  620. }
  621. accs := ks.Accounts()
  622. if len(accs) <= index {
  623. return accounts.Account{}, fmt.Errorf("index %d higher than number of accounts %d", index, len(accs))
  624. }
  625. return accs[index], nil
  626. }
  627. // setEtherbase retrieves the etherbase either from the directly specified
  628. // command line flags or from the keystore if CLI indexed.
  629. func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
  630. if ctx.GlobalIsSet(EtherbaseFlag.Name) {
  631. account, err := MakeAddress(ks, ctx.GlobalString(EtherbaseFlag.Name))
  632. if err != nil {
  633. Fatalf("Option %q: %v", EtherbaseFlag.Name, err)
  634. }
  635. cfg.Etherbase = account.Address
  636. return
  637. }
  638. accounts := ks.Accounts()
  639. if (cfg.Etherbase == common.Address{}) {
  640. if len(accounts) > 0 {
  641. cfg.Etherbase = accounts[0].Address
  642. } else {
  643. log.Warn("No etherbase set and no accounts found as default")
  644. }
  645. }
  646. }
  647. // MakePasswordList reads password lines from the file specified by the global --password flag.
  648. func MakePasswordList(ctx *cli.Context) []string {
  649. path := ctx.GlobalString(PasswordFileFlag.Name)
  650. if path == "" {
  651. return nil
  652. }
  653. text, err := ioutil.ReadFile(path)
  654. if err != nil {
  655. Fatalf("Failed to read password file: %v", err)
  656. }
  657. lines := strings.Split(string(text), "\n")
  658. // Sanitise DOS line endings.
  659. for i := range lines {
  660. lines[i] = strings.TrimRight(lines[i], "\r")
  661. }
  662. return lines
  663. }
  664. func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
  665. setNodeKey(ctx, cfg)
  666. setNAT(ctx, cfg)
  667. setListenAddress(ctx, cfg)
  668. setDiscoveryV5Address(ctx, cfg)
  669. setBootstrapNodes(ctx, cfg)
  670. setBootstrapNodesV5(ctx, cfg)
  671. if ctx.GlobalIsSet(MaxPeersFlag.Name) {
  672. cfg.MaxPeers = ctx.GlobalInt(MaxPeersFlag.Name)
  673. }
  674. if ctx.GlobalIsSet(MaxPendingPeersFlag.Name) {
  675. cfg.MaxPendingPeers = ctx.GlobalInt(MaxPendingPeersFlag.Name)
  676. }
  677. if ctx.GlobalIsSet(NoDiscoverFlag.Name) || ctx.GlobalBool(LightModeFlag.Name) {
  678. cfg.NoDiscovery = true
  679. }
  680. // if we're running a light client or server, force enable the v5 peer discovery
  681. // unless it is explicitly disabled with --nodiscover note that explicitly specifying
  682. // --v5disc overrides --nodiscover, in which case the later only disables v4 discovery
  683. forceV5Discovery := (ctx.GlobalBool(LightModeFlag.Name) || ctx.GlobalInt(LightServFlag.Name) > 0) && !ctx.GlobalBool(NoDiscoverFlag.Name)
  684. if ctx.GlobalIsSet(DiscoveryV5Flag.Name) {
  685. cfg.DiscoveryV5 = ctx.GlobalBool(DiscoveryV5Flag.Name)
  686. } else if forceV5Discovery {
  687. cfg.DiscoveryV5 = true
  688. }
  689. if netrestrict := ctx.GlobalString(NetrestrictFlag.Name); netrestrict != "" {
  690. list, err := netutil.ParseNetlist(netrestrict)
  691. if err != nil {
  692. Fatalf("Option %q: %v", NetrestrictFlag.Name, err)
  693. }
  694. cfg.NetRestrict = list
  695. }
  696. if ctx.GlobalBool(DevModeFlag.Name) {
  697. // --dev mode can't use p2p networking.
  698. cfg.MaxPeers = 0
  699. cfg.ListenAddr = ":0"
  700. cfg.DiscoveryV5Addr = ":0"
  701. cfg.NoDiscovery = true
  702. cfg.DiscoveryV5 = false
  703. }
  704. }
  705. // SetNodeConfig applies node-related command line flags to the config.
  706. func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
  707. SetP2PConfig(ctx, &cfg.P2P)
  708. setIPC(ctx, cfg)
  709. setHTTP(ctx, cfg)
  710. setWS(ctx, cfg)
  711. setNodeUserIdent(ctx, cfg)
  712. switch {
  713. case ctx.GlobalIsSet(DataDirFlag.Name):
  714. cfg.DataDir = ctx.GlobalString(DataDirFlag.Name)
  715. case ctx.GlobalBool(DevModeFlag.Name):
  716. cfg.DataDir = filepath.Join(os.TempDir(), "ethereum_dev_mode")
  717. case ctx.GlobalBool(TestnetFlag.Name):
  718. cfg.DataDir = filepath.Join(node.DefaultDataDir(), "testnet")
  719. case ctx.GlobalBool(RinkebyFlag.Name):
  720. cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby")
  721. }
  722. if ctx.GlobalIsSet(KeyStoreDirFlag.Name) {
  723. cfg.KeyStoreDir = ctx.GlobalString(KeyStoreDirFlag.Name)
  724. }
  725. if ctx.GlobalIsSet(LightKDFFlag.Name) {
  726. cfg.UseLightweightKDF = ctx.GlobalBool(LightKDFFlag.Name)
  727. }
  728. if ctx.GlobalIsSet(NoUSBFlag.Name) {
  729. cfg.NoUSB = ctx.GlobalBool(NoUSBFlag.Name)
  730. }
  731. }
  732. func setGPO(ctx *cli.Context, cfg *gasprice.Config) {
  733. if ctx.GlobalIsSet(GpoBlocksFlag.Name) {
  734. cfg.Blocks = ctx.GlobalInt(GpoBlocksFlag.Name)
  735. }
  736. if ctx.GlobalIsSet(GpoPercentileFlag.Name) {
  737. cfg.Percentile = ctx.GlobalInt(GpoPercentileFlag.Name)
  738. }
  739. }
  740. func setEthash(ctx *cli.Context, cfg *eth.Config) {
  741. if ctx.GlobalIsSet(EthashCacheDirFlag.Name) {
  742. cfg.EthashCacheDir = ctx.GlobalString(EthashCacheDirFlag.Name)
  743. }
  744. if ctx.GlobalIsSet(EthashDatasetDirFlag.Name) {
  745. cfg.EthashDatasetDir = ctx.GlobalString(EthashDatasetDirFlag.Name)
  746. }
  747. if ctx.GlobalIsSet(EthashCachesInMemoryFlag.Name) {
  748. cfg.EthashCachesInMem = ctx.GlobalInt(EthashCachesInMemoryFlag.Name)
  749. }
  750. if ctx.GlobalIsSet(EthashCachesOnDiskFlag.Name) {
  751. cfg.EthashCachesOnDisk = ctx.GlobalInt(EthashCachesOnDiskFlag.Name)
  752. }
  753. if ctx.GlobalIsSet(EthashDatasetsInMemoryFlag.Name) {
  754. cfg.EthashDatasetsInMem = ctx.GlobalInt(EthashDatasetsInMemoryFlag.Name)
  755. }
  756. if ctx.GlobalIsSet(EthashDatasetsOnDiskFlag.Name) {
  757. cfg.EthashDatasetsOnDisk = ctx.GlobalInt(EthashDatasetsOnDiskFlag.Name)
  758. }
  759. }
  760. func checkExclusive(ctx *cli.Context, flags ...cli.Flag) {
  761. set := make([]string, 0, 1)
  762. for _, flag := range flags {
  763. if ctx.GlobalIsSet(flag.GetName()) {
  764. set = append(set, "--"+flag.GetName())
  765. }
  766. }
  767. if len(set) > 1 {
  768. Fatalf("flags %v can't be used at the same time", strings.Join(set, ", "))
  769. }
  770. }
  771. // SetEthConfig applies eth-related command line flags to the config.
  772. func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
  773. // Avoid conflicting network flags
  774. checkExclusive(ctx, DevModeFlag, TestnetFlag, RinkebyFlag)
  775. checkExclusive(ctx, FastSyncFlag, LightModeFlag, SyncModeFlag)
  776. ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
  777. setEtherbase(ctx, ks, cfg)
  778. setGPO(ctx, &cfg.GPO)
  779. setEthash(ctx, cfg)
  780. switch {
  781. case ctx.GlobalIsSet(SyncModeFlag.Name):
  782. cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
  783. case ctx.GlobalBool(FastSyncFlag.Name):
  784. cfg.SyncMode = downloader.FastSync
  785. case ctx.GlobalBool(LightModeFlag.Name):
  786. cfg.SyncMode = downloader.LightSync
  787. }
  788. if ctx.GlobalIsSet(LightServFlag.Name) {
  789. cfg.LightServ = ctx.GlobalInt(LightServFlag.Name)
  790. }
  791. if ctx.GlobalIsSet(LightPeersFlag.Name) {
  792. cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name)
  793. }
  794. if ctx.GlobalIsSet(NetworkIdFlag.Name) {
  795. cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
  796. }
  797. // Ethereum needs to know maxPeers to calculate the light server peer ratio.
  798. // TODO(fjl): ensure Ethereum can get MaxPeers from node.
  799. cfg.MaxPeers = ctx.GlobalInt(MaxPeersFlag.Name)
  800. if ctx.GlobalIsSet(CacheFlag.Name) {
  801. cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name)
  802. }
  803. cfg.DatabaseHandles = makeDatabaseHandles()
  804. if ctx.GlobalIsSet(MinerThreadsFlag.Name) {
  805. cfg.MinerThreads = ctx.GlobalInt(MinerThreadsFlag.Name)
  806. }
  807. if ctx.GlobalIsSet(DocRootFlag.Name) {
  808. cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
  809. }
  810. if ctx.GlobalIsSet(ExtraDataFlag.Name) {
  811. cfg.ExtraData = []byte(ctx.GlobalString(ExtraDataFlag.Name))
  812. }
  813. if ctx.GlobalIsSet(GasPriceFlag.Name) {
  814. cfg.GasPrice = GlobalBig(ctx, GasPriceFlag.Name)
  815. }
  816. if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
  817. // TODO(fjl): force-enable this in --dev mode
  818. cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)
  819. }
  820. // Override any default configs for hard coded networks.
  821. switch {
  822. case ctx.GlobalBool(TestnetFlag.Name):
  823. if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
  824. cfg.NetworkId = 3
  825. }
  826. cfg.Genesis = core.DefaultTestnetGenesisBlock()
  827. case ctx.GlobalBool(RinkebyFlag.Name):
  828. if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
  829. cfg.NetworkId = 4
  830. }
  831. cfg.Genesis = core.DefaultRinkebyGenesisBlock()
  832. case ctx.GlobalBool(DevModeFlag.Name):
  833. cfg.Genesis = core.DevGenesisBlock()
  834. if !ctx.GlobalIsSet(GasPriceFlag.Name) {
  835. cfg.GasPrice = new(big.Int)
  836. }
  837. cfg.PowTest = true
  838. }
  839. // TODO(fjl): move trie cache generations into config
  840. if gen := ctx.GlobalInt(TrieCacheGenFlag.Name); gen > 0 {
  841. state.MaxTrieCacheGen = uint16(gen)
  842. }
  843. }
  844. // RegisterEthService adds an Ethereum client to the stack.
  845. func RegisterEthService(stack *node.Node, cfg *eth.Config) {
  846. var err error
  847. if cfg.SyncMode == downloader.LightSync {
  848. err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
  849. return les.New(ctx, cfg)
  850. })
  851. } else {
  852. err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
  853. fullNode, err := eth.New(ctx, cfg)
  854. if fullNode != nil && cfg.LightServ > 0 {
  855. ls, _ := les.NewLesServer(fullNode, cfg)
  856. fullNode.AddLesServer(ls)
  857. }
  858. return fullNode, err
  859. })
  860. }
  861. if err != nil {
  862. Fatalf("Failed to register the Ethereum service: %v", err)
  863. }
  864. }
  865. // RegisterShhService configures Whisper and adds it to the given node.
  866. func RegisterShhService(stack *node.Node) {
  867. if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisper.New(), nil }); err != nil {
  868. Fatalf("Failed to register the Whisper service: %v", err)
  869. }
  870. }
  871. // RegisterEthStatsService configures the Ethereum Stats daemon and adds it to
  872. // th egiven node.
  873. func RegisterEthStatsService(stack *node.Node, url string) {
  874. if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
  875. // Retrieve both eth and les services
  876. var ethServ *eth.Ethereum
  877. ctx.Service(&ethServ)
  878. var lesServ *les.LightEthereum
  879. ctx.Service(&lesServ)
  880. return ethstats.New(url, ethServ, lesServ)
  881. }); err != nil {
  882. Fatalf("Failed to register the Ethereum Stats service: %v", err)
  883. }
  884. }
  885. // SetupNetwork configures the system for either the main net or some test network.
  886. func SetupNetwork(ctx *cli.Context) {
  887. // TODO(fjl): move target gas limit into config
  888. params.TargetGasLimit = new(big.Int).SetUint64(ctx.GlobalUint64(TargetGasLimitFlag.Name))
  889. }
  890. // MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
  891. func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
  892. var (
  893. cache = ctx.GlobalInt(CacheFlag.Name)
  894. handles = makeDatabaseHandles()
  895. )
  896. name := "chaindata"
  897. if ctx.GlobalBool(LightModeFlag.Name) {
  898. name = "lightchaindata"
  899. }
  900. chainDb, err := stack.OpenDatabase(name, cache, handles)
  901. if err != nil {
  902. Fatalf("Could not open database: %v", err)
  903. }
  904. return chainDb
  905. }
  906. func MakeGenesis(ctx *cli.Context) *core.Genesis {
  907. var genesis *core.Genesis
  908. switch {
  909. case ctx.GlobalBool(TestnetFlag.Name):
  910. genesis = core.DefaultTestnetGenesisBlock()
  911. case ctx.GlobalBool(RinkebyFlag.Name):
  912. genesis = core.DefaultRinkebyGenesisBlock()
  913. case ctx.GlobalBool(DevModeFlag.Name):
  914. genesis = core.DevGenesisBlock()
  915. }
  916. return genesis
  917. }
  918. // MakeChain creates a chain manager from set command line flags.
  919. func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chainDb ethdb.Database) {
  920. var err error
  921. chainDb = MakeChainDatabase(ctx, stack)
  922. engine := ethash.NewFaker()
  923. if !ctx.GlobalBool(FakePoWFlag.Name) {
  924. engine = ethash.New("", 1, 0, "", 1, 0)
  925. }
  926. config, _, err := core.SetupGenesisBlock(chainDb, MakeGenesis(ctx))
  927. if err != nil {
  928. Fatalf("%v", err)
  929. }
  930. vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)}
  931. chain, err = core.NewBlockChain(chainDb, config, engine, new(event.TypeMux), vmcfg)
  932. if err != nil {
  933. Fatalf("Can't create BlockChain: %v", err)
  934. }
  935. return chain, chainDb
  936. }
  937. // MakeConsolePreloads retrieves the absolute paths for the console JavaScript
  938. // scripts to preload before starting.
  939. func MakeConsolePreloads(ctx *cli.Context) []string {
  940. // Skip preloading if there's nothing to preload
  941. if ctx.GlobalString(PreloadJSFlag.Name) == "" {
  942. return nil
  943. }
  944. // Otherwise resolve absolute paths and return them
  945. preloads := []string{}
  946. assets := ctx.GlobalString(JSpathFlag.Name)
  947. for _, file := range strings.Split(ctx.GlobalString(PreloadJSFlag.Name), ",") {
  948. preloads = append(preloads, common.AbsolutePath(assets, strings.TrimSpace(file)))
  949. }
  950. return preloads
  951. }
  952. // MigrateFlags sets the global flag from a local flag when it's set.
  953. // This is a temporary function used for migrating old command/flags to the
  954. // new format.
  955. //
  956. // e.g. geth account new --keystore /tmp/mykeystore --lightkdf
  957. //
  958. // is equivalent after calling this method with:
  959. //
  960. // geth --keystore /tmp/mykeystore --lightkdf account new
  961. //
  962. // This allows the use of the existing configuration functionality.
  963. // When all flags are migrated this function can be removed and the existing
  964. // configuration functionality must be changed that is uses local flags
  965. func MigrateFlags(action func(ctx *cli.Context) error) func(*cli.Context) error {
  966. return func(ctx *cli.Context) error {
  967. for _, name := range ctx.FlagNames() {
  968. if ctx.IsSet(name) {
  969. ctx.GlobalSet(name, ctx.String(name))
  970. }
  971. }
  972. return action(ctx)
  973. }
  974. }