flags.go 4.5 KB

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