flags.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. This file is part of go-ethereum
  3. go-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. go-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /**
  15. * @authors
  16. * Jeffrey Wilcke <i@jev.io>
  17. */
  18. package main
  19. import (
  20. "flag"
  21. "fmt"
  22. "log"
  23. "os"
  24. "os/user"
  25. "path"
  26. "github.com/ethereum/go-ethereum/logger"
  27. "github.com/ethereum/go-ethereum/vm"
  28. )
  29. var (
  30. Identifier string
  31. KeyRing string
  32. DiffTool bool
  33. DiffType string
  34. KeyStore string
  35. StartRpc bool
  36. StartWebSockets bool
  37. RpcPort int
  38. NatType string
  39. PMPGateway string
  40. OutboundPort string
  41. ShowGenesis bool
  42. AddPeer string
  43. MaxPeer int
  44. GenAddr bool
  45. UseSeed bool
  46. SecretFile string
  47. ExportDir string
  48. NonInteractive bool
  49. Datadir string
  50. LogFile string
  51. ConfigFile string
  52. DebugFile string
  53. LogLevel int
  54. Dump bool
  55. DumpHash string
  56. DumpNumber int
  57. VmType int
  58. ImportChain string
  59. SHH bool
  60. Dial bool
  61. PrintVersion bool
  62. )
  63. // flags specific to cli client
  64. var (
  65. StartMining bool
  66. StartJsConsole bool
  67. InputFile string
  68. )
  69. func defaultDataDir() string {
  70. usr, _ := user.Current()
  71. return path.Join(usr.HomeDir, ".ethereum")
  72. }
  73. var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini")
  74. func Init() {
  75. flag.Usage = func() {
  76. fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0])
  77. flag.PrintDefaults()
  78. }
  79. flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
  80. flag.StringVar(&Identifier, "id", "", "Custom client identifier")
  81. flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
  82. flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
  83. flag.StringVar(&OutboundPort, "port", "30303", "listening port")
  84. flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)")
  85. flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for PMP")
  86. flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
  87. flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on")
  88. flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
  89. flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
  90. flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
  91. flag.BoolVar(&UseSeed, "seed", true, "seed peers")
  92. flag.BoolVar(&SHH, "shh", true, "whisper protocol (on)")
  93. flag.BoolVar(&Dial, "dial", true, "dial out connections (on)")
  94. flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
  95. flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
  96. flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
  97. flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
  98. flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
  99. flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
  100. flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
  101. flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
  102. flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
  103. flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
  104. flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
  105. flag.StringVar(&ImportChain, "chain", "", "Imports given chain")
  106. flag.BoolVar(&Dump, "dump", false, "output the ethereum state in JSON format. Sub args [number, hash]")
  107. flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
  108. flag.IntVar(&DumpNumber, "number", -1, "specify arg in number")
  109. flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
  110. flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
  111. flag.BoolVar(&PrintVersion, "version", false, "prints version number")
  112. flag.Parse()
  113. if VmType >= int(vm.MaxVmTy) {
  114. log.Fatal("Invalid VM type ", VmType)
  115. }
  116. InputFile = flag.Arg(0)
  117. }