flags.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. "path/filepath"
  27. "runtime"
  28. "bitbucket.org/kardianos/osext"
  29. "github.com/ethereum/go-ethereum/logger"
  30. "github.com/ethereum/go-ethereum/vm"
  31. )
  32. var (
  33. Identifier string
  34. KeyRing string
  35. KeyStore string
  36. PMPGateway string
  37. StartRpc bool
  38. StartWebSockets bool
  39. RpcPort int
  40. UseUPnP bool
  41. NatType string
  42. OutboundPort string
  43. ShowGenesis bool
  44. AddPeer string
  45. MaxPeer int
  46. GenAddr bool
  47. UseSeed bool
  48. SecretFile string
  49. ExportDir string
  50. NonInteractive bool
  51. Datadir string
  52. LogFile string
  53. ConfigFile string
  54. DebugFile string
  55. LogLevel int
  56. VmType int
  57. )
  58. // flags specific to gui client
  59. var AssetPath string
  60. //TODO: If we re-use the one defined in cmd.go the binary osx image crashes. If somebody finds out why we can dry this up.
  61. func defaultAssetPath() string {
  62. var assetPath string
  63. // If the current working directory is the go-ethereum dir
  64. // assume a debug build and use the source directory as
  65. // asset directory.
  66. pwd, _ := os.Getwd()
  67. if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist") {
  68. assetPath = path.Join(pwd, "assets")
  69. } else {
  70. switch runtime.GOOS {
  71. case "darwin":
  72. // Get Binary Directory
  73. exedir, _ := osext.ExecutableFolder()
  74. assetPath = filepath.Join(exedir, "../Resources")
  75. case "linux":
  76. assetPath = "/usr/share/mist"
  77. case "windows":
  78. assetPath = "./assets"
  79. default:
  80. assetPath = "."
  81. }
  82. }
  83. return assetPath
  84. }
  85. func defaultDataDir() string {
  86. usr, _ := user.Current()
  87. return path.Join(usr.HomeDir, ".mist")
  88. }
  89. var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini")
  90. func Init() {
  91. flag.Usage = func() {
  92. fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0])
  93. flag.PrintDefaults()
  94. }
  95. flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
  96. flag.StringVar(&Identifier, "id", "", "Custom client identifier")
  97. flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
  98. flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
  99. flag.StringVar(&OutboundPort, "port", "30303", "listening port")
  100. flag.BoolVar(&UseUPnP, "upnp", true, "enable UPnP support")
  101. flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
  102. flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on")
  103. flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
  104. flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
  105. flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
  106. flag.BoolVar(&UseSeed, "seed", true, "seed peers")
  107. flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
  108. flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)")
  109. flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
  110. flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
  111. flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
  112. flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
  113. flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for PMP")
  114. flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
  115. flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
  116. flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
  117. flag.StringVar(&AssetPath, "asset_path", defaultAssetPath(), "absolute path to GUI assets directory")
  118. flag.Parse()
  119. if VmType >= int(vm.MaxVmTy) {
  120. log.Fatal("Invalid VM type ", VmType)
  121. }
  122. }